0

I am new with MATLAB and trying to implement the following step of License Plate Localization:

Vertical Gradient Computation

Here's my progress so far.

Code:

[rows,cols] = size(img);
image_gradient = zeros(rows,cols);

for i =1:1:rows
    for j =1:1:cols-1
        image_gradient(i,j) = abs( img(i,j+1) - img(i,j) );
    end
end

figure,imshow(image_gradient);title('Gradient');

Output:

Output of gradient computation

I will be indeed grateful if someone can guide me what I am doing wrong here.

Raj Kumar
  • 67
  • 9
  • What makes you say you're doing something wrong? It could be a matter of scaling the resulting image. Try using the sample image with your algorithm and see if you get something similar. – E. Schiesser Feb 24 '16 at 17:16
  • I got the same kind of output when I applied my algorithm on the sample image – Raj Kumar Feb 24 '16 at 18:34

1 Answers1

3

Well to start off you should understand that illumination is a pain in the backside. And you shall understand that as you keep learning new algorithms.

Looking at your first set of images you can see that the plate is a prominent part of the image. Number plates are designed to give this contrast between the characters and the background. Moreover the entire background is fairly smooth. When you look at the image on the bottom there are a lot of artifacts and sharp intensity transitions, This should explain why your gradient is noisy.

What you are essentilly trying to do is a filtering operation ( Or Convolution ) using a filter that looks like this [-1 1]. Look up matlab functions conv2 and filter.

To reduce the noise you should be performing an averaging operation along with the gradient. This will reduce the susceptibility to noise. So your final filter would look something like this [-1 1;-1 1;-1 1]. Make sure your filter values are normalized if your are trying other complex filters.

Detecting number plates is not easy with the proposed method. It should definitely get you started. But you really need to start reading up on some more algorithms.

  • Thanks a lot for time and consideration to my problem :) What I understood from the answer is that **there is no mistake in the code** and the reason behind the _noisy output_ is the _sharp intensity transitions_ in the input image.. So I should apply `conv2` for smoothing the image before computing the gradients. Please elaborate the term `normalization` with the perspective of a filter. – Raj Kumar Feb 24 '16 at 18:26
  • You are correct. A smoothening operation should reduce the gradients . Normalization is peformed to ensure that any filter that you use with an image adds up to 1 so that there is no gain introduced to the intensity. This is usually done by summing the filter taps and dividing each taps in the kernel by this sum. It does not apply to your gradient filter since the sum is already 0. – Midhun Harikumar Feb 25 '16 at 19:37
  • Hmm, Thanks a lot for the response, I have applied `vertical gradient` and then `horizontal gradient` on the output of `vertical gradient` computation and now my image looks much similar to the sample output. – Raj Kumar Feb 25 '16 at 19:41