Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edge detection and segmentation

I am trying to extract an object from a paper currency image. On the original image I applied sobel edge detection. Here is the image:

enter image description here

My question is in the following cropped image I want to have only the number 100 displayed with out the other noises. How can I do that please?

enter image description here

The code I used so far is:

close All;
clear All;
Note1 = imread('0001.jpg');
Note2 = imread('0007.jpg');
figure(1), imshow(Note1);
figure(2), imshow(Note2);

Note1=rgb2gray(Note1);
Note2=rgb2gray(Note2);
Edge1=edge(Note1,'sobel');
Edge2=edge(Note2,'sobel');
figure(5), imshow(Edge1),title('Edge sobel1');
figure(6), imshow(Edge2),title('Edge sobel2');

rect_Note1 = [20 425 150 70];
rect_Note2 = [20 425 150 70];
sub_Note1 = imcrop(Edge1,rect_Note1);
sub_Note2 = imcrop(Edge2,rect_Note2);
figure(7), imshow(sub_Note1);
figure(8), imshow(sub_Note2);

For completeness, the original image:

like image 518
user3472037 Avatar asked Oct 21 '22 06:10

user3472037


1 Answers

Use a Gaussian filter to clean up the noise before applying the edge detector:

% Create the gaussian filter with hsize = [5 5] and sigma = 3.5
G = fspecial('gaussian',[7 7], 3.5);
Note1f = imfilter(Note1,G,'same');
Edge1f=edge(Note1f,'sobel');
sub_Note1f = imcrop(Edge1f,rect_Note1);
figure(6), imshow(sub_Note1f);

This results in a much cleaner 100 image enter image description here

You could also use a Canny edge detector instead of the Sobel transform.

Edge1c = edge(Note1,'canny', [0.2, 0.4] , 3.5);
sub_Note1c = imcrop(Edge1c,rect_Note1);
figure(7), imshow(sub_Note1c);

enter image description here

like image 183
Bull Avatar answered Oct 23 '22 00:10

Bull