Assignment#2 Image Processing
Assignment#2 Image Processing
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:
OUTPUT: