SlideShare a Scribd company logo
Using MATLAB (code must be written for MATLAB) and the concept of Hough
Transformations.
Create an image containing 4 distinct points, 3 of which are collinear, the 4th not collinear. Plan
how to attack this problem, looking specifically for the line with the most collinear points. Write
code to find the line formed by the 3 points.
Thank you for any help you are able to provide.
Solution
The Hough transform is powerful method to detect the edges in the computer visison developed
by Paul Hough in 1962, in order to solve this problem we need to create a GUI for the same.
We need to first create an image or upload an image to the system and then detect all the possible
edges in the system and then use cvhough and cvunhough functions which i have defined below
in this project
Matlab Code for CVImageGet
function P = CVImageGet
[P,W] = get_image_file( '*.bmp,*.gif,*.jpeq', 'choose the file format');
if
W==0
I=[ ];// there is no image input to the system
else
WP=[W,P];
ext=WP(findstr(WP,'.')+1:end);
if
strcmp(ext,'pgm')
I = readpgm(WP);
else
%matlab image types
[Im,MAP]=imread(PF);
I = ind2gray(Im,MAP);
end
I = I/max(I(:));
end
function CV Edge
function edgedata = CVEdge(I,M,T,A);
if
M>2
error(
'M should be 1(subpixel) or 2(edge)'
);
elseif
M==1
%SUBPIXEL
edgedata=[];
for
rownr = 1:size(I,1);
row = I(rownr,:);
edgeposfine=rowedges(row,A,T);
26
edgedata=[edgedata
[edgeposfine;rownr*ones(size(edgeposfine))]];
end
;
elseif
M==2
%EDGE
switch
A
case
1,
meth=
'sobel'
;
case
2,
meth=
'prewitt'
;
case
3,
meth=
'roberts'
;
case
4,
meth=
'log'
;
case
5,
meth=
'zerocross'
;
case
6,
meth=
'canny'
;
otherwise
,
error(
'edge method values only 1 through 6'
);
end
E=edge(I,meth,T);
[r,c]=find(E);
edgedata=[c';r'];
end
Function CVhough
function [H,m,b] = CVhough(edgedata,nT,nS)
MAXDIST=1.2;
if
nargin<1
error(
'require at least one input argument: binary image'
)
elseif
nargin<2
warning(
'defualt value of 200 assigned to number of orientations
nT'
)
nT=200;
warning([
'defualt value of'
, max(edgedata(:))*MAXDIST,
'assigned
to number of orientations nS'
])
nS=max(edgedata(:))*MAXDIST;
elseif
nargin<3
warning([
'defualt value of'
, max(edgedata(:))*MAXDIST,
'assigned
to number of orientations nS'
])
nS=max(edgedata(:))*MAXDIST;
end
row=edgedata(2,:)';
col=edgedata(1,:)';
%defining the range of the orientations of line
Ts=[0:pi/nT:pi-pi/nT]';
27
%cos and sin of all the angles
CsT=cos(Ts);
SnT=sin(Ts);
%solving for distances for all orientations at all nonzero pixels
%size of S is: [length(row) , length(Ts)]
S=row*CsT' + col*SnT';
%mapping:
%
Smin = min(S(:))--> 1
%
Smax = max(S(:))--> nS
%gives (y=mx+b):
%
m=(nS-1)/(Smax-Smin)
%
b=(Smax-nS*Smin)/(Smax-Smin)
%and then round it and get rounded mapped S:rmS
Smin=min(S(:));
Smax=max(S(:));
m =(nS-1)/(Smax-Smin);
b =(Smax-nS*Smin)/(Smax-Smin);
rmS=round(m*S + b);
%Note:
H is [nT,nS]
%
rmS is
[nP,nT] nP:number of edge points
H=[];
hw=waitbar(0,
'Performing Hough Transform...'
);
for
k=1:nS,
isEq=(rmS==k);
%
H=[H,sum(isEq)']; %sum(isEq) 1 x nT
H(:,k)=sum(isEq)';
waitbar(k/nS,hw);
end
close(hw);
CV unhough Code
function [SL,TL,intSL,intTL]=CVunhough(H,m,b,P)
DILATEFRAC=.02;
if
nargin<3
error(
'require at least 3 input arguments: histogram matrix H, 2
distance mapping parameters m & b'
);
elseif
nargin<4
warning(
'defualt value of 0.7 assigned to percentage threshold
P'
);
P=0.7;
end
[nT,nS]=size(H);
TH=im2bw(H,P*max(H(:)));
H1=dilate(TH,ones(round(DILATEFRAC*size(H))),1);
L=bwlabel(H1,8);
n=max(L(:));
intSL=[]; intTL=[];
for
k=1:n,
[r,c]=find(L==k);
intTL=[intTL; mean(r)];
intSL=[intSL; mean(c)];
end
TL=(intTL-1)*pi/nT;
SL=(intSL-b)/m;
disp(
'Selected lines in the form [a b c]'
)
disp(
'----------------------------------'
)
for
k=1:n,
a=num2str(cos(TL(k)));
b=num2str(sin(TL(k)));
c=num2str(-SL(k));
disp(['Line ',num2str(k),'/',num2str(n),': [ ',a,' ',b,' ',c,']']);
end

More Related Content

DOC
图像分割算法基础
PPTX
Introduction to Image Processing with MATLAB
PDF
ECE 565 Project1
PDF
HodgeCyce
PDF
Digital image processing using matlab: basic transformations, filters and ope...
PDF
Test
PDF
Problem Solving by Computer Finite Element Method
PDF
Templateless Marked Element Recognition Using Computer Vision
图像分割算法基础
Introduction to Image Processing with MATLAB
ECE 565 Project1
HodgeCyce
Digital image processing using matlab: basic transformations, filters and ope...
Test
Problem Solving by Computer Finite Element Method
Templateless Marked Element Recognition Using Computer Vision

Similar to Using MATLAB (code must be written for MATLAB) and the concept of Ho.pdf (20)

DOCX
PDF
Lec09 hough
PPTX
Computer Vision Introduction
PDF
Practical Digital Image Processing 3
PPT
cv1.ppt
PPTX
Basics of Linear Hough Transform
PPTX
Line Detection using Hough transform .pptx
PPT
hough.edv;lrtgkmbopp4tyol;trmgkoperitgbkbkevppt
PDF
line and circle detection using hough transform
PDF
Test
PPTX
Canny Edge & Image Representation.pptx
PPTX
Linear Hough TRansform
PDF
Implementation_of_Hough_Transform_for_image_processing_applications.pdf
PDF
Test
PDF
Resolution project
PDF
Solutions_Manual_to_accompany_Applied_Nu.pdf
PDF
A Hough Transform Implementation for Line Detection for a Mobile Robot Self-N...
PDF
F017663344
PDF
Test
Lec09 hough
Computer Vision Introduction
Practical Digital Image Processing 3
cv1.ppt
Basics of Linear Hough Transform
Line Detection using Hough transform .pptx
hough.edv;lrtgkmbopp4tyol;trmgkoperitgbkbkevppt
line and circle detection using hough transform
Test
Canny Edge & Image Representation.pptx
Linear Hough TRansform
Implementation_of_Hough_Transform_for_image_processing_applications.pdf
Test
Resolution project
Solutions_Manual_to_accompany_Applied_Nu.pdf
A Hough Transform Implementation for Line Detection for a Mobile Robot Self-N...
F017663344
Test
Ad

More from donohovalentinj6 (20)

PDF
Explain what factors underlying the signaling specificity and the sp.pdf
PDF
Create the Version class          - data members (integers)     .pdf
PDF
Can anyone help me with this oneWhich falls outside the study of .pdf
PDF
As the sender of important or critical information, what actions sh.pdf
PDF
1. Montessori schools emphasizeA. group activities and projects.pdf
PDF
Compare and contrast woven and secondary cortical bone. Mention 4 si.pdf
PDF
The hardness of bone is primarily due to a combination of collagen an.pdf
PDF
The following statements are on general IO operations and Interrupts.pdf
PDF
Sympatric speciation is _____.initiated by the appearance of a geogr.pdf
PDF
What is the evolutionary advantage of an exoskeleton A. it waterpro.pdf
PDF
What is the probability that 5 out of 7 offspring in a monohybrid F2.pdf
PDF
What are the characteristics of lifeSolutionAnswerChatac.pdf
PDF
What all does the SHOW statement do in MySQLSolutionAs the co.pdf
PDF
three fossils are found in undisturbed layers of rock, or strata. Fo.pdf
PDF
Use the rank correlation coefficient to test for a correlation betwe.pdf
PDF
Think about what you now know about project delivery systems. Are th.pdf
PDF
The brain stem is the link between what two parts What two structur.pdf
PDF
SQL(workbench) Write a script that contains the CREATE TABLE statem.pdf
PDF
Since 1942, Ernst Mayr defined species as populations that can re.pdf
PDF
Question Help More Info The beginning inventory numbers are as follow.pdf
Explain what factors underlying the signaling specificity and the sp.pdf
Create the Version class          - data members (integers)     .pdf
Can anyone help me with this oneWhich falls outside the study of .pdf
As the sender of important or critical information, what actions sh.pdf
1. Montessori schools emphasizeA. group activities and projects.pdf
Compare and contrast woven and secondary cortical bone. Mention 4 si.pdf
The hardness of bone is primarily due to a combination of collagen an.pdf
The following statements are on general IO operations and Interrupts.pdf
Sympatric speciation is _____.initiated by the appearance of a geogr.pdf
What is the evolutionary advantage of an exoskeleton A. it waterpro.pdf
What is the probability that 5 out of 7 offspring in a monohybrid F2.pdf
What are the characteristics of lifeSolutionAnswerChatac.pdf
What all does the SHOW statement do in MySQLSolutionAs the co.pdf
three fossils are found in undisturbed layers of rock, or strata. Fo.pdf
Use the rank correlation coefficient to test for a correlation betwe.pdf
Think about what you now know about project delivery systems. Are th.pdf
The brain stem is the link between what two parts What two structur.pdf
SQL(workbench) Write a script that contains the CREATE TABLE statem.pdf
Since 1942, Ernst Mayr defined species as populations that can re.pdf
Question Help More Info The beginning inventory numbers are as follow.pdf
Ad

Recently uploaded (20)

PDF
RMMM.pdf make it easy to upload and study
PDF
Computing-Curriculum for Schools in Ghana
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Institutional Correction lecture only . . .
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Cell Types and Its function , kingdom of life
PPTX
Pharma ospi slides which help in ospi learning
PDF
01-Introduction-to-Information-Management.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Pre independence Education in Inndia.pdf
RMMM.pdf make it easy to upload and study
Computing-Curriculum for Schools in Ghana
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
TR - Agricultural Crops Production NC III.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
human mycosis Human fungal infections are called human mycosis..pptx
Final Presentation General Medicine 03-08-2024.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
Institutional Correction lecture only . . .
PPH.pptx obstetrics and gynecology in nursing
Cell Types and Its function , kingdom of life
Pharma ospi slides which help in ospi learning
01-Introduction-to-Information-Management.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Pre independence Education in Inndia.pdf

Using MATLAB (code must be written for MATLAB) and the concept of Ho.pdf

  • 1. Using MATLAB (code must be written for MATLAB) and the concept of Hough Transformations. Create an image containing 4 distinct points, 3 of which are collinear, the 4th not collinear. Plan how to attack this problem, looking specifically for the line with the most collinear points. Write code to find the line formed by the 3 points. Thank you for any help you are able to provide. Solution The Hough transform is powerful method to detect the edges in the computer visison developed by Paul Hough in 1962, in order to solve this problem we need to create a GUI for the same. We need to first create an image or upload an image to the system and then detect all the possible edges in the system and then use cvhough and cvunhough functions which i have defined below in this project Matlab Code for CVImageGet function P = CVImageGet [P,W] = get_image_file( '*.bmp,*.gif,*.jpeq', 'choose the file format'); if W==0 I=[ ];// there is no image input to the system else WP=[W,P]; ext=WP(findstr(WP,'.')+1:end); if strcmp(ext,'pgm') I = readpgm(WP); else %matlab image types [Im,MAP]=imread(PF); I = ind2gray(Im,MAP); end I = I/max(I(:)); end function CV Edge
  • 2. function edgedata = CVEdge(I,M,T,A); if M>2 error( 'M should be 1(subpixel) or 2(edge)' ); elseif M==1 %SUBPIXEL edgedata=[]; for rownr = 1:size(I,1); row = I(rownr,:); edgeposfine=rowedges(row,A,T); 26 edgedata=[edgedata [edgeposfine;rownr*ones(size(edgeposfine))]]; end ; elseif M==2 %EDGE switch A case 1, meth= 'sobel' ; case 2, meth= 'prewitt' ; case 3,
  • 3. meth= 'roberts' ; case 4, meth= 'log' ; case 5, meth= 'zerocross' ; case 6, meth= 'canny' ; otherwise , error( 'edge method values only 1 through 6' ); end E=edge(I,meth,T); [r,c]=find(E); edgedata=[c';r']; end Function CVhough function [H,m,b] = CVhough(edgedata,nT,nS) MAXDIST=1.2; if nargin<1 error( 'require at least one input argument: binary image' )
  • 4. elseif nargin<2 warning( 'defualt value of 200 assigned to number of orientations nT' ) nT=200; warning([ 'defualt value of' , max(edgedata(:))*MAXDIST, 'assigned to number of orientations nS' ]) nS=max(edgedata(:))*MAXDIST; elseif nargin<3 warning([ 'defualt value of' , max(edgedata(:))*MAXDIST, 'assigned to number of orientations nS' ]) nS=max(edgedata(:))*MAXDIST; end row=edgedata(2,:)'; col=edgedata(1,:)'; %defining the range of the orientations of line Ts=[0:pi/nT:pi-pi/nT]'; 27 %cos and sin of all the angles CsT=cos(Ts); SnT=sin(Ts); %solving for distances for all orientations at all nonzero pixels %size of S is: [length(row) , length(Ts)] S=row*CsT' + col*SnT'; %mapping:
  • 5. % Smin = min(S(:))--> 1 % Smax = max(S(:))--> nS %gives (y=mx+b): % m=(nS-1)/(Smax-Smin) % b=(Smax-nS*Smin)/(Smax-Smin) %and then round it and get rounded mapped S:rmS Smin=min(S(:)); Smax=max(S(:)); m =(nS-1)/(Smax-Smin); b =(Smax-nS*Smin)/(Smax-Smin); rmS=round(m*S + b); %Note: H is [nT,nS] % rmS is [nP,nT] nP:number of edge points H=[]; hw=waitbar(0, 'Performing Hough Transform...' ); for k=1:nS, isEq=(rmS==k); % H=[H,sum(isEq)']; %sum(isEq) 1 x nT H(:,k)=sum(isEq)'; waitbar(k/nS,hw); end close(hw); CV unhough Code function [SL,TL,intSL,intTL]=CVunhough(H,m,b,P) DILATEFRAC=.02;
  • 6. if nargin<3 error( 'require at least 3 input arguments: histogram matrix H, 2 distance mapping parameters m & b' ); elseif nargin<4 warning( 'defualt value of 0.7 assigned to percentage threshold P' ); P=0.7; end [nT,nS]=size(H); TH=im2bw(H,P*max(H(:))); H1=dilate(TH,ones(round(DILATEFRAC*size(H))),1); L=bwlabel(H1,8); n=max(L(:)); intSL=[]; intTL=[]; for k=1:n, [r,c]=find(L==k); intTL=[intTL; mean(r)]; intSL=[intSL; mean(c)]; end TL=(intTL-1)*pi/nT; SL=(intSL-b)/m; disp( 'Selected lines in the form [a b c]' ) disp( '----------------------------------' ) for k=1:n,