Skip to content

Commit cfbe890

Browse files
author
Cristy
committed
Render hough lines in-place
1 parent 9c99a27 commit cfbe890

File tree

2 files changed

+69
-6
lines changed

2 files changed

+69
-6
lines changed

MagickCore/cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ static MagickBooleanType ClonePixelCacheRepository(
707707

708708
if (status == MagickFalse)
709709
continue;
710-
if (y == (ssize_t) clone_info->rows)
710+
if (y >= (ssize_t) clone_info->rows)
711711
continue;
712712
region.width=cache_info->columns;
713713
region.height=1;

MagickCore/feature.c

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,69 @@ static inline double MagickRound(double x)
17601760
return(ceil(x));
17611761
}
17621762

1763+
static Image *RenderHoughLines(const ImageInfo *image_info,const size_t columns,
1764+
const size_t rows,ExceptionInfo *exception)
1765+
{
1766+
#define BoundingBox "viewbox"
1767+
1768+
DrawInfo
1769+
*draw_info;
1770+
1771+
Image
1772+
*image;
1773+
1774+
MagickBooleanType
1775+
status;
1776+
1777+
/*
1778+
Open image.
1779+
*/
1780+
image=AcquireImage(image_info,exception);
1781+
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
1782+
if (status == MagickFalse)
1783+
{
1784+
image=DestroyImageList(image);
1785+
return((Image *) NULL);
1786+
}
1787+
image->columns=columns;
1788+
image->rows=rows;
1789+
draw_info=CloneDrawInfo(image_info,(DrawInfo *) NULL);
1790+
draw_info->affine.sx=image->resolution.x == 0.0 ? 1.0 : image->resolution.x/
1791+
DefaultResolution;
1792+
draw_info->affine.sy=image->resolution.y == 0.0 ? 1.0 : image->resolution.y/
1793+
DefaultResolution;
1794+
image->columns=(size_t) (draw_info->affine.sx*image->columns);
1795+
image->rows=(size_t) (draw_info->affine.sy*image->rows);
1796+
status=SetImageExtent(image,image->columns,image->rows,exception);
1797+
if (status == MagickFalse)
1798+
return(DestroyImageList(image));
1799+
if (SetImageBackgroundColor(image,exception) == MagickFalse)
1800+
{
1801+
image=DestroyImageList(image);
1802+
return((Image *) NULL);
1803+
}
1804+
/*
1805+
Render drawing.
1806+
*/
1807+
if (GetBlobStreamData(image) == (unsigned char *) NULL)
1808+
draw_info->primitive=FileToString(image->filename,~0UL,exception);
1809+
else
1810+
{
1811+
draw_info->primitive=(char *) AcquireMagickMemory((size_t)
1812+
GetBlobSize(image)+1);
1813+
if (draw_info->primitive != (char *) NULL)
1814+
{
1815+
(void) CopyMagickMemory(draw_info->primitive,GetBlobStreamData(image),
1816+
(size_t) GetBlobSize(image));
1817+
draw_info->primitive[GetBlobSize(image)]='\0';
1818+
}
1819+
}
1820+
(void) DrawImage(image,draw_info,exception);
1821+
draw_info=DestroyDrawInfo(draw_info);
1822+
(void) CloseBlob(image);
1823+
return(GetFirstImageInList(image));
1824+
}
1825+
17631826
MagickExport Image *HoughLineImage(const Image *image,const size_t width,
17641827
const size_t height,const size_t threshold,ExceptionInfo *exception)
17651828
{
@@ -1911,8 +1974,8 @@ MagickExport Image *HoughLineImage(const Image *image,const size_t width,
19111974
(double) height,(double) threshold);
19121975
if (write(file,message,strlen(message)) != (ssize_t) strlen(message))
19131976
status=MagickFalse;
1914-
(void) FormatLocaleString(message,MagickPathExtent,"viewbox 0 0 %.20g %.20g\n",
1915-
(double) image->columns,(double) image->rows);
1977+
(void) FormatLocaleString(message,MagickPathExtent,
1978+
"viewbox 0 0 %.20g %.20g\n",(double) image->columns,(double) image->rows);
19161979
if (write(file,message,strlen(message)) != (ssize_t) strlen(message))
19171980
status=MagickFalse;
19181981
line_count=image->columns > image->rows ? image->columns/4 : image->rows/4;
@@ -2008,7 +2071,7 @@ MagickExport Image *HoughLineImage(const Image *image,const size_t width,
20082071
*/
20092072
image_info=AcquireImageInfo();
20102073
image_info->background_color=image->background_color;
2011-
(void) FormatLocaleString(image_info->filename,MagickPathExtent,"mvg:%s",path);
2074+
(void) FormatLocaleString(image_info->filename,MagickPathExtent,"%s",path);
20122075
artifact=GetImageArtifact(image,"background");
20132076
if (artifact != (const char *) NULL)
20142077
(void) SetImageOption(image_info,"background",artifact);
@@ -2021,7 +2084,7 @@ MagickExport Image *HoughLineImage(const Image *image,const size_t width,
20212084
artifact=GetImageArtifact(image,"strokewidth");
20222085
if (artifact != (const char *) NULL)
20232086
(void) SetImageOption(image_info,"strokewidth",artifact);
2024-
lines_image=ReadImage(image_info,exception);
2087+
lines_image=RenderHoughLines(image_info,image->columns,image->rows,exception);
20252088
artifact=GetImageArtifact(image,"hough-lines:accumulator");
20262089
if ((lines_image != (Image *) NULL) &&
20272090
(IsStringTrue(artifact) != MagickFalse))
@@ -2061,7 +2124,7 @@ MagickExport Image *HoughLineImage(const Image *image,const size_t width,
20612124
% computes a new x,y centroid from those coordinates and a new mean. This new
20622125
% x,y centroid is used as the center for a new window. This process iterates
20632126
% until it converges and the final mean is replaces the (original window
2064-
% center) pixel value. It repeats this process for the next pixel, etc.,
2127+
% center) pixel value. It repeats this process for the next pixel, etc.,
20652128
% until it processes all pixels in the image. Results are typically better with
20662129
% colorspaces other than sRGB. We recommend YIQ, YUV or YCbCr.
20672130
%

0 commit comments

Comments
 (0)