Horizontal Projection of the Histogram
Mostra commenti meno recenti
i am using matlab for the ligature recognition and i want to get the horizontal Histogram projection of the Image so that i can segment the Lines can any one guide me regarding this
here is my code
close all;
clear all
clc;
imtool close all; % Close all figure windows created by imtool.
workspace; % Make sure the workspace panel is showing.
I = imread('C:\Users\ENZEE\Desktop\MUS\shah.jpg');
Im=im2double(I);%use to double the precision of the Image
Ir=imresize(Im,[100 150]);
%figure,imshow(Ir), title('Extracted Image');
text(size(I,2),size(I,1)+15, ...
'Image courtesy', ...
'FontSize',7,'HorizontalAlignment','right');
text(size(Ir,2),size(Ir,1)+25, ....
'Trying.........', ...
'FontSize',7,'HorizontalAlignment','right');
I = imnoise(Ir,'salt & pepper',0.02);
K = medfilt2(Ir);
%imshow(Ir), title('Noise Image'), figure, imshow(K), title('Filtered Image');
%otsu's method
[level EM]= graythresh(K);
%display(level)
BW = im2bw(K,level);
%figure, imshow(BW),title('Converted Image');
[imx,imy]=size(BW);
%imhist(K), title('Histogram')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%Segmentation%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
numofpixels=size(I,1)*size(I,2);% size(image array,dimensions)
L=bwlabel(BW);%L = bwlabel(BW, n) returns a matrix L, of the same size as BW,
%containing labels for the connected objects in BW.
mn=min(L);
%disp('~~~~~~~~~~~~~~~~~~~~~~~~~~MIN~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
%disp(mn)
%disp('~~~~~~~~~~~~~~~~~~~~~~~~~FINDED~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
fd=find(mn<1);
%disp(fd)
%disp('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
calc=length(fd)/numofpixels;
disp(length(fd))
disp(numofpixels)
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%[r c]=size(BW);
%contour = bwtraceboundary(BW, [r,c], 'W', 8, 50,...
% 'counterclockwise');
%STATS = regionprops(BW,'FilledArea');
% seD = strel('arbitrary',numofpixels);
% BWfinal = imerode(BW,seD);
% BWfinal = imerode(BW,seD);
% %figure, imshow(BWfinal), title('segmented image');
% BWoutline = bwperim(BWfinal);
% Segout = Ir;
% Segout(BWoutline) = 255;
%figure, imshow(Segout), title('outlined original image');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%NEW TRY%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure
subplot(2,2,1)
hist(BW)
subplot(2,2,2)
barh(~BW,2)
% [pixelCount grayLevels] = imhist(BW);
%
%
%
% bar(pixelCount); title('Histogram of original image');
% xlim([0 grayLevels(end)]); % Scale x axis manually.
%x1=size(I,1);
%y1=size(I,2)
%disp(STATS)
%crp= imcontour(BW,150);
%figure,imshow(crp),title('Manually Image')
%crp=imcrop(BW);
%imcontour(crp,2);
%figure,imshow(crp),title('Manually Croped Image')
%a=bwperim(BW);
%imshow(a)
%bwdist()
%disp(calc)
%a=imcontour(I,2);
%imshow(a)
%CR=imcrop(BW,'rect');
%figure,imshow(CR)
%t=wpdec2(BW,2,'db1');
%plot(t)
% figure;
% hi=hist(BW);
% hi1=hi(1:2:256);
% horz=1:2:256;
% bar(horz,hi);
% axis([0 255 0 1400]);
% set(gca, 'xtick', 0:50:255);
% set(gca, 'ytick', 0:2000:15000);
% xlabel('Gray level' );
% ylabel('No of pixels' );
% title('Histogram before opening the image');
}
5 Commenti
Walter Roberson
il 13 Giu 2012
http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
Assad
il 15 Giu 2012
sayar chit
il 14 Ott 2017
thanks for answering
sayar chit
il 14 Ott 2017
Your answer isn't quite clear so if you have clean suggestion for lines,words and character segmentation, give me my account (chitsanlwin.maths.mm@gmailcom). I wish you good luck and health for your whole life
Walter Roberson
il 19 Ott 2017
sayar chit, who were you addressing that to? Whose answer is not quite clear? Which answer? What are some of the parts you are finding confusing?
Risposte (2)
Walter Roberson
il 15 Giu 2012
hist(sum(double(BW),2))
18 Commenti
Assad
il 16 Giu 2012
Walter Roberson
il 16 Giu 2012
Do you want a histogram of the projection, or a projection of the histogram? Histograms are usually 1D graphics, so a horizontal projection of a histogram would normally be a single box. The code I gave was for the histogram of the projection.
Image Analyst
il 16 Giu 2012
I don't know what this means either. The "horizontal Projection of the Histogram" would be just a single bar. Or, if you summed it horizontally across bins, you'd get a 1D array the meaning of which I'm not quite sure how to interpret and not sure why you'd want it. You need to explain further, if you can't figure it out yourself.
Assad
il 17 Giu 2012
Image Analyst
il 17 Giu 2012
I'm still not sure what you want but it sounds like maybe you need to research "automatic threshold methods."
Assad
il 17 Giu 2012
Image Analyst
il 17 Giu 2012
I suggest you look at papers published by those who have done it successfully already: http://iris.usc.edu/Vision-Notes/bibliography/contentschar.html#OCR,%20Document%20Analysis%20and%20Character%20Recognition%20Systems
Assad
il 18 Giu 2012
Image Analyst
il 18 Giu 2012
I don't know who told you that Extent is the list of pixels in the blob. It is not. PixelValues is. Plus, it's not the bounding box either. BoundingBox is. I'm sorry you feel that the published methods are too difficult. Robust algorithms tend to be complicated if they are to handle lots of different situations.
Walter Roberson
il 18 Giu 2012
Too many errors in that code to bother to explain.
mp = regionprops(BW, 'All');
for K = 1 : length(mp)
Box = mp(K).BoundingBox;
subImage = imcrop(BW,Box);
subplot(2,2,3)
imshow(subImage);
drawnow();
end
Walter Roberson
il 18 Giu 2012
Going back to your "histogram" question:
H = sum(double(BW),2);
H *is* now the histogram. Divide the rows up at places where H is 0 or very low in order to get an estimate of where the lines of text are.
Assad
il 18 Giu 2012
Image Analyst
il 18 Giu 2012
linesWithText = H < 50; % Or whatever value works.
linesWithText will be true (1) for image rows where there are lots of white pixels in a line, and false (0) where there are not.
Walter Roberson
il 19 Giu 2012
I think that should be H > 50 (or whatever value works).
Assad
il 20 Giu 2012
Image Analyst
il 20 Giu 2012
The text was dark blobs on a light background so that's why I used H < 50. I think graythresh() sets bright pixels to 1 and dark pixels to 0. So the text would have low values and the background high values when you do a sum horizontally of the binary image. I still think that looking at successful methods others have developed is the way to go.
Walter Roberson
il 20 Giu 2012
Hmmm, I would assume that the foreground and background would have been reversed somewhere along the way, or else the regionprops() and labeling are going to produce pretty useless information. I guess that wasn't a good assumption.
The assignment to H and the thresholding against 50 (or whatever works) done on that, could go anywhere after the bwopenarea() and before the "for a".
I notice that the "for a" code has not been repaired even though I gave specific replacement code :(
Assad
il 25 Giu 2012
Image Analyst
il 25 Giu 2012
0 voti
I don't know if you have to use that algorithm, but there are plenty to choose from. How about this one:
2 Commenti
Assad
il 30 Giu 2012
Walter Roberson
il 30 Giu 2012
Modificato: Walter Roberson
il 30 Giu 2012
If H is your row histogram,
first = find(H >= 10, 1, 'first');
last = find(H >= 10, 1, 'last');
cropped_image = YourImage(first:last, :);
Categorie
Scopri di più su Display Image in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!