0% found this document useful (0 votes)
62 views5 pages

Robotics Lectures-1 For Final Year Indir

The document contains MATLAB code to perform Hough transform and Otsu's thresholding on images. The Hough transform code reads an image, converts it to grayscale, finds edges using Canny edge detection, performs Hough transform to find lines, and plots the original image with edges and Hough transform results. The Otsu's thresholding code reads an image, converts to grayscale, computes a histogram, calculates the threshold using Otsu's method, converts the image to binary using the threshold, and displays the results.

Uploaded by

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

Robotics Lectures-1 For Final Year Indir

The document contains MATLAB code to perform Hough transform and Otsu's thresholding on images. The Hough transform code reads an image, converts it to grayscale, finds edges using Canny edge detection, performs Hough transform to find lines, and plots the original image with edges and Hough transform results. The Otsu's thresholding code reads an image, converts to grayscale, computes a histogram, calculates the threshold using Otsu's method, converts the image to binary using the threshold, and displays the results.

Uploaded by

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

Hough Transform:

Matlab Code:
I = imread('a3.jpg');
I=rgb2gray(I);
BW = edge(I,'canny');
[H,T,R] = hough(BW);
P = houghpeaks(H,2);
figure
imshow(I);
title('Original Image');
figure
imshow(BW);
title('Edges');
figure
imshow(H,[],'XData',T,'YData',R,'InitialMagnification','fit');
xlabel('\theta'), ylabel('\rho');
axis on, axis normal, hold on;
plot(T(P(:,2)),R(P(:,1)),'s','color','white');

Output:
OTSU Thresholding Method:
MATLAB CODE:
I=imread('l7.jpg');
I=rgb2gray(I);
figure(1)
imshow(I);
figure(2)
imhist(I);
n=imhist(I);
N=sum(n);
max=0;
for i=1:256
P(i)=n(i)/N;
end

for T=2:255
w0=sum(P(1:T));
w1=sum(P(T+1:256));
u0=dot([0:T-1],P(1:T))/w0;
u1=dot([T:255],P(T+1:256))/w1;
sigma=w0*w1*((u1-u0)^2);
if sigma>max
max=sigma;
threshold=T-1;
end
end

bw=im2bw(I,threshold/255);
figure(3)
imshow(bw);

OUTPUT:

You might also like