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

11 vues (au cours des 30 derniers jours)
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 commentaires
Ayaz Wazir
Ayaz Wazir le 16 Fév 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.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 15 Fév 2017
Easiest way: transpose the image before passing it to the existing routine.
  1 commentaire
Walter Roberson
Walter Roberson le 16 Fév 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');

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by