Horizontal Projection of the Histogram

8 次查看(过去 30 天)
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 个评论
sayar chit
sayar chit 2017-10-14
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
Walter Roberson 2017-10-19
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?

请先登录,再进行评论。

回答(2 个)

Walter Roberson
Walter Roberson 2012-6-15
hist(sum(double(BW),2))
  18 个评论
Walter Roberson
Walter Roberson 2012-6-20
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
Assad 2012-6-25
what is BWopenarea() ?
are you talking about bwareaopen() i was thinking if i can segment the lines on the be half of thresolds\histograms whats the techniques of doing that

请先登录,再进行评论。


Image Analyst
Image Analyst 2012-6-25
I don't know if you have to use that algorithm, but there are plenty to choose from. How about this one:
  2 个评论
Assad
Assad 2012-6-30
can you suggest me how to crop on the basis of Histogram values such as crop all those who are less than in Histogram
Walter Roberson
Walter Roberson 2012-6-30
编辑:Walter Roberson 2012-6-30
If H is your row histogram,
first = find(H >= 10, 1, 'first');
last = find(H >= 10, 1, 'last');
cropped_image = YourImage(first:last, :);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by