Example:Hough transform/MATLAB: Difference between revisions

m
Fixed syntax highlighting.
(use Programming-example-page template)
m (Fixed syntax highlighting.)
 
(One intermediate revision by one other user not shown)
Line 1:
=={{Programming-example-page|Hough transform|language=MATLAB}}==
 
This solution takes an image and the theta resolution as inputs. The image itself must be a 2-D boolean array. This array is constructed such that all of the pixels on an edge have the value "true." This can be done for a normal image using an "edge finding" algorithm to preprocess the image. In the case of the example image the pentagon "edges" are black pixels. So when the image is imported into MATLAB simply say any pixel colored black is true. The syntax is usually, cdata < 255. Where the vale 255 represents white and 0 represents black.
 
<langsyntaxhighlight MATLABlang="matlab">function [rho,theta,houghSpace] = houghTransform(theImage,thetaSampleFrequency)
 
%Define the hough space
Line 46:
colormap('gray');
 
end</langsyntaxhighlight>
 
Sample Usage:
<langsyntaxhighlight MATLABlang="matlab">>> uiopen('C:\Documents and Settings\owner\Desktop\Chris\MATLAB\RosettaCode\180px-Pentagon.png',1)
>> houghTransform(cdata(:,:,1)<255,1/200); %The image from uiopen is stored in cdata. The reason why the image is cdata<255 is because the "edge" pixels are black.</langsyntaxhighlight>
[[Image:HoughTransformHex.png|thumb|left|360x200px|Image produced by MATLAB implementation of the Hough transform when applied to the sample pentagon image.]]
<br style="clear:both" />
9,483

edits