0% found this document useful (0 votes)
88 views

Assignment#2 Image Processing

The document describes code for line and circle detection in images using Hough transforms. It first shows code for line detection that reads an image, detects edges, performs Hough transform by incrementing an accumulator for each point-slope pair, and extracts the highest value in the accumulator to find the detected line. It then shows code for circle detection that similarly reads an image, detects edges, discretizes radii and angles to increment the accumulator, thresholds the accumulator, and finds centroids to detect circles and plot them on the original image.

Uploaded by

pradeep G
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views

Assignment#2 Image Processing

The document describes code for line and circle detection in images using Hough transforms. It first shows code for line detection that reads an image, detects edges, performs Hough transform by incrementing an accumulator for each point-slope pair, and extracts the highest value in the accumulator to find the detected line. It then shows code for circle detection that similarly reads an image, detects edges, discretizes radii and angles to increment the accumulator, thresholds the accumulator, and finds centroids to detect circles and plot them on the original image.

Uploaded by

pradeep G
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

NAME: PRADEEP GOPALSAMY STUDENT ID: 110087307

ASSIGNMENT – 2
IMAGE PROCESSING
LINE
DETECTION
CODE :
%% Line Detection [x,y] = th = [diag_id, theta_id] =
Code: size(EDGE_I); %% theta(theta_id) ;%% ind2sub(size(accuml
%% Function X,Y Coordinates of gradient value ator), I); %%
Initialization the pixels of image % the gradient angle in
function line = %Diagonal of the diagonal given image
line_detection(I) input image representation plot(theta(theta_id),d
diag_lim = r= iag(diag_id),'o','Line
%Read an image and norm([x,y]); % i*cos(th) + j*sin(th) ; Width',3);
Store pixel values in Diagonal detection %% Polar hold off;
a variable in matrix using mean of X and representation of the
format Y coordinate diagonal line rho % Compute the line
inputimage = diag = (- value coordinates
imread('test1.jpg'); diag_lim:1:diag_lim) diag_id =
; round(r+ m=-
%Converting RGB %Gradiant in Radius number_diags/2); (cos(theta(theta_id))/
PIXEL to grayscale theta = sin(theta(theta_id)));
image (0:theta_sample_freq accumlator(diag_id, b = (diag(diag_id)) /
Img_G = :pi); theta_id)= sin(theta(theta_id));
rgb2gray(inputimage number_thetas = accumlator(diag_id, % x coordinates
); numel(theta); theta_id) +1; x = 1:x;
number_diags = end % y coordinates
% Applying edge numel(diag); end y = m*x+b; %% (m -
detection on the end slope) find straight
grayscale image %Accumulator i.e end line in image
EDGE_I = Hough Space
edge(Img_G,"canny" accumlator = % Hough Transform % Plot the detected
); zeros(number_diags, line super imposed
number_thetas); figure; on original
%Display the edge imagesc(theta,diag,a figure;
image on separate % Perform Hough ccumlator); subplot(1,2,1)
window Space title('Hough imagesc(EDGE_I);
imshow(EDGE_I); Transform in GIven colormap(gray);
% Picture Edge for i = 1:x % i value image'); title("Line Detection
Detection varies from 1 to x - xlabel('Theta in Canny image")
title('Canny Edge co-ordinate value of (radians)'); hold on;
Detected image'); % image ylabel('diag line = plot(y,x, 'r',
Title of the Picture for j = 1:y % j (pixels)'); 'LineWidth',3)
value varies from 1 colormap('gray'); subplot(1,2,2)
% to x - co-ordinate hold on; imagesc(inputimage)
PARAMETERIZAT value of image ;
ION % if this is an % Extract the colormap(gray);
edge point parameters title("Line Detection
%Quantization of the if in original image")
step size EDGE_I(i,j)== 1 % Detecting one line hold on;
theta_sample_freq = for theta_id = [M, I] = line= plot(y,x,'r',
0.01; % Incremental 1:number_thetas max(accumlator(:)); 'LineWidth',3)
step size by 0.01 % the % Accumulator
%Input image gradiant angle % It's coordinates in end
dimension HT Space
OUTPUT:

FIGURE: 1 CANNY EDGE DETECTION ON ORIGNAL IMAGE

FIGURE:2 DIAGONAL LINE DETECTION

FIGURE:3 HOUGH TRANSFORM ON GIVEN IMAGE


CIRCLE DETECTION n(inputimage,ra 'canny',[0.02 acc=zeros(rows,
CODE: dius) 0.44]); columns);

Img=imread('tes %image size %perform Hough


t2.jpg'); i= [rows,columns]= transform
radius=[26,30,3 rgb2gray(Img); size(edge_image for x=1:columns
1]; edge_image = );% input image for y=1:rows
%centures = edge(i, dimension
circle_detectio %accumulator if(edge_image(y
,x)==1) % end ones(6,6)); radius values
detect edge end %Dilating in centroids
points frim the end imshow(temp,[0
binary edge end max(max(temp))] % Drawing
image end ); circles
for temp = xCenter =
ang=0:360 % imerode(temp,on [centroids(:,1)
discretized %show Hough es(3,3)); ];
theta transform %Eroding yCenter =
figure(1) imshow(temp,[0 [centroids(:,2)
t=(ang*pi)/180; imagesc(b,a, max(max(temp))] ];
for acc); ); centures =
g=1:3 % for title('Hough s = [xCenter,yCente
loop run the Transform'); regionprops(im2 r] % showing
input radius xlabel('a'); bw(temp),'centr the x and y
values ylabel('b'); oid','Perimeter values of the
radius=[26,30,3 colormap('gray' '); %Computing centure of
1,32]; ); hold on; centroid , circles
Center of mass
r=radius(g); of the region for
%Thresholding centroids = a=1:length(cent
a=round(x- and get the cat(1, roids(:,1)) %
r*cos(t)); % center of the s.Centroid);%Cr Draw circles
'a' convert to circle. eate and
hough space close all; concatenate two theta = 0 :
temp = acc; matrices 0.01 : 2*pi;
b=round(y- temp(find(temp< vertically, x = 30*
r*sin(t)); % 250))=0; then cos(theta) +
'b' convert to %Thresholding horizontally. xCenter(a);
hough space (make zero y = 30*
anything below figure(2) sin(theta) +
if(a & b) value of 250 in imshow(i); yCenter(a);
the hold on; plot(x,
acc(b,a)=acc(b, accumulator) plot(centroids( y,'r','LineWidt
a)+1; % store imshow(temp,[0 :,1), h',3);
values in the max(temp(:))]) centroids(:,2),
accumulator temp = '*b')% plot by end
end imdilate(temp, taking stored

OUTPUT:

FIGURE:4 CANNY EDGE DETECTION OF ALL COINS IN GIVEN IMAGE


FIGURE:5 COIN RADIUS DETECTION USING CENTER

Circle Detection using R X1 = (1:x); figure;


Y1 = (1:y); imagesc(accumlator);
(Radius) value:
%Accumulator i.e Hough title('Hough
I="test2.jpg"; Space Transform');
R=[28]; accumlator = xlabel('a');
C = zeros(x,y); ylabel('b');
circle_detection(I,R); r=R; colormap('gray');hold
%%circle_detection % Perform Hough Space on;
Function: for i=1:x % Extract the
function C = for j=1:y parameters
circle_detection(I,R) % if this is an edge [M, I]= max(accumlator
%Read an image point (:));
Img= imread(I); if % It's coordinates in
%Converting to edge_Img(i,j)==1 HT Space
grayscale image for [a, b] = ind2sub (size
Img_G=rgb2gray(Img); thetaId= 1:numThetas (accumlator), I);
% Applying edge % the gradiant angle plot(Y1(b),
detection on the X1(a),'*','LineWidth',1
grayscale image th=theta(thetaId); );
edge_Img = % the a and b hold off;
edge(Img_G,'canny'); representation % Center coordinates
%Display the edge image C = [Y1(b), X1(a)];
imshow(edge_Img) a=round(i-r*cos(th)); % Draw circle
title('Edge image'); figure;
b=round(j-r*sin(th)); imshow(Img);
% PARAMETERIZATION hold on;
%Quantization of the if(a>0&&a<=x&&b>0&&b<=y theta = 0 : 0.01 :
step size ) 2*pi;
theta_frequency= 0.01; y = R* cos(theta) +
%Gradiant in Radius accumlator(a,b) = X1(a);
theta=(0:theta_frequenc accumlator(a,b)+1; x = R* sin(theta) +
y:2*pi); end Y1(b);
numThetas=numel end plot(x,
(theta); end y,'r','LineWidth',3);
%Input image dimension end title('circle with
[x,y] = size (edge_Img) end radius R on original
size (edge_Img) % Show the Hough image');
Transform end
OUTPUT:

(R=28 X=563 Y=224)

FIGURE:6&7 HOUGH TRANSFORM FOR DETECTED RADIUS 28

(R=30, X=337, Y=457)

FIGURE:8&9 HOUGH TRANSFORM FOR DETECTED RADIUS 30

(R=33, X=67, Y=568)

FIGURE:10&11 HOUGH TRANSFORM FOR DETECTED RADIUS 33

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy