问题
suppose i have an image in which there are some letters.based on those letters of the image i want to show the vertical projections of histogram of the given image in an axes:
i tried imhist('image')
but its not showing the projection its only giving a white box on my GUI axes
a=imhist(Iedge2);
imshow(a,'Parent',handles.axes2);
title('HISTOGRAM OF DILATED IMAGE')
in this iedge2
is the inverted binary image.
after getting the vertical histogram I want to segment the inverted binary image into vertical segments as the words of sentence/ letters of the word, where there are less or no white pixels I am not getting how to do please help sir after applying your code i am getting the following output
i have combined the screenshots in a single snapshot so that will be easy to u to see in a single image of outputs
回答1:
First of all, you are not looking for a "vertical histogram", but rather a bar plot of vertical sum.
Here's a simplified example.
Consider this input image
You can read and threshold it
img = imread('http://i.stack.imgur.com/3YonG.png')
bw = img(:,:,1)<128; %// convert to binary, text = 1
Now you can inspect the vertical sum
sc = sum(bw,1); %// sum columns
figure;bar(sc);
As you can see if there are more than ~2 pixels set in a column - this is probably a letter. We can use this threshold
rm = sc > 2;
cs = cumsum(~rm).*rm; %// assign unique value to each "letter" columns
mask = bsxfun(@times, bw, cs ); %// seperate the letters in the mask
Resulting with
回答2:
This is the code i was looking for my question
clear all;
cd('C:\Users\IFIM\Desktop\New folder\KANND_HAND_SET');
myFolder = 'C:\Users\IFIM\Desktop\segment';
[filename, pathname] = uigetfile('*.bmp','Select image to be read.');
i= imread(fullfile(pathname,filename));
i=padarray(i,[0 10]);
verticalProjection = sum(i, 1);
set(gcf, 'Name', 'DEMO BY SOUMYADEEP', 'NumberTitle', 'Off')
subplot(2, 2, 1);imshow(i);
subplot(2,2,3);
plot(verticalProjection, 'b-');
grid on;
t = verticalProjection;
t(t==0) = inf;
mayukh=min(t)
% 0 where there is background, 1 where there are letters
letterLocations = verticalProjection > mayukh;
% Find Rising and falling edges
d = diff(letterLocations);
startingColumns = find(d>0);
endingColumns = find(d<0);
% Extract each region
y=1;
for k = 1 : length(startingColumns)
% Get sub image of just one character...
subImage = i(:, startingColumns(k):endingColumns(k));
[L,num] = bwlabel(subImage);
for z= 1 : num
bw= ismember( L, z);
% Construct filename for this particular image.
baseFileName = sprintf('curvedimage %d.png', y);
y=y+1;
% Prepend the folder to make the full file name.
fullFileName = fullfile(myFolder, baseFileName);
% Do the write to disk.
imwrite(bw, fullFileName);
subplot(2,2,4);
pause(2);
imshow(bw);
end;
y=y+1;
end;
来源:https://stackoverflow.com/questions/37308235/how-to-get-an-vertical-histogram-of-an-binary-image-and-based-on-that-histogram