필터 지우기
필터 지우기

Horizontal Projection of the Histogram

조회 수: 8 (최근 30일)
Assad
Assad 2012년 6월 13일
댓글: Walter Roberson 2017년 10월 19일
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