Alfi Nugraha
Alfi Nugraha

Reputation: 9

How to perfom horizontal rank filtering for edge detection?

I do some recognizing of plate numbers, but I'm stuck when doing extraction on them. I read references that state I have to perform horizontal rank filtering but I don't know how to do it.

Code:

a = imread('Izy.jpg');
b = imresize(a,0.5);
c = rgb2gray(b);
Py = [ -1,0,1; -1,0,1 ; -1,0,1];        
Gp = conv2(c,Py);
Gpx = edge(Gp,'prewitt');
cl = bwareaopen(Gpx,10);
imshow(cl)

Izy.jpg

output image and i want get the red rectangled that i mark then crop it

I've read references that say we have to use vertical edge prewitt; I'm using horizontal rank filtering to extract the plate number.

Upvotes: 0

Views: 332

Answers (1)

nahomyaja
nahomyaja

Reputation: 202

I just tried a code to work for this particular image, but not a general one. Here we have the input image.

Original Image

a = imread('Izy.jpg');
b = imresize(a,0.5);
c = rgb2gray(b);

The code until here reads the image into variable a, scales it down to half the size (stored in b) and then converts it from a 3 channel image to grayscale (stored in c). I would suggest to use Canny edge detector over Prewitt detector as follows:

Gpx = edge(c,'canny');
L = bwlabel(Gpx,8);

Edge Detected Image

  • The edge detected binary image (stored in Gpx) will have several foreground images or regions. A region is a collection of pixels, which each of the member pixels connected to at least 1 of it's 8 neighboring pixels. These regions be labeled with the use of bwlabel() and stored in L.
  • Using regionprops('properties','properties',..), we get a structure with different properties of the regions present in the image.

Here, area and eccentricity properties are calculated for the regions. eccentricity values helps us identify is a region is a circular or linear. For circle, the value is 0 and for a line, the value is 1

imgstat = regionprops(L,'Area','Eccentricity');
area = [imgstat.Area];
ecc = [imgstat.Eccentricity];

Since we have 129 (size(imgstat)) regions in the image, each region will have some area and eccentricity values. Use trial and error to identify the required values for area and eccentricity properties.

Apply the approximate property values to get the boundary of the license plate, and store the region index in label. logical_result extracts and stores the required region from the labeled image.

label = find((area > 150) & (ecc < 0.95) & (ecc > 0.9));
logical_result = ismember(L,label);
figure;imshow(logical_result)

The image stored in logical_result

Extracted regions

Now, calculate the boundary values fromlogical_result. These values are recovered as indices and so, we have to convert them into subscripts using ind2sub(). From the boundary values we can extract the region of interest from the original image

[row, col] = ind2sub([size(c,1), size(c,2)],find(logical_result == 1));
result = c(min(row):max(row),min(col):max(col));
imshow(result);

This gives the following result:

Output Obtained

Upvotes: 0

Related Questions