How can i calculate vertical histogram. I took a code from somewhere which works for Horizontal processing but how i change it to work for vertical processing. The code is below

14 views (last 30 days)
img=rgb2gray(imread('n3.jpg'));
[rows,cols] = size(img);
img2 = zeros(rows,cols);
%Calculated the gradients
for i =1:1:rows
for j =1:1:cols-1
img2(i,j) = abs(img(i,j+1) - img(i,j));
end
end
% calculated the mean of gradients to determine which pixels hold the value
% that is above the average difference as the paper says `Then the average
% gradient variance is calculated and compared with each other. The bigger
% intensity variations provide the rough estimation of license plate region.`
M = mean2(img2);
for i =1:1:rows
for j =1:1:cols-1
if(abs(img(i,j+1) - img(i,j))<M)
img2(i,j)=0;
else
img2(i,j)=100;
end
end
end
% Applied average filter to reduce the noise
img2 = filter2(fspecial('average',2),img2)/255;
% Output is shown
figure,imshow(img2);title('Gradient');
  2 Comments
Ayaz Wazir
Ayaz Wazir on 16 Feb 2017
Dear Walter Roberson i used your proposed method i mean "Transpose of image'" for vertical image processing but couldn't get the required result. my reqiured result is to extract the object after vertical processing as like the third object in sumit gupta image which i uploaded.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 15 Feb 2017
Easiest way: transpose the image before passing it to the existing routine.
  1 Comment
Walter Roberson
Walter Roberson on 16 Feb 2017
img=rgb2gray(imread('n3.jpg'));
[rows,cols] = size(img);
img2 = zeros(rows,cols);
%Calculated the gradients
for i =1:1:rows-1
for j =1:1:cols
img2(i,j) = abs(img(i+1,j) - img(i,j));
end
end
% calculated the mean of gradients to determine which pixels hold the value
% that is above the average difference as the paper says `Then the average
% gradient variance is calculated and compared with each other. The bigger
% intensity variations provide the rough estimation of license plate region.`
M = mean2(img2);
for i =1:1:rows-1
for j =1:1:cols
if(im2(i,j)<M)
img2(i,j)=0;
else
img2(i,j)=100;
end
end
end
% Applied average filter to reduce the noise
img2 = filter2(fspecial('average',2),img2)/255;
% Output is shown
figure,imshow(img2);title('Gradient');

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!