使用水平直方图轮廓分割字符行

时间:2016-06-04 20:10:14

标签: matlab image-processing histogram image-segmentation

我想细分图像中的水平行字符,如图所示

input image that i have taken histogram of taken image

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;

在这段代码中垂直分割正在发生,但我想要的是从段落中获取水平线,以便在请求帮助后完成此垂直分割 谢谢和问候

1 个答案:

答案 0 :(得分:2)

您需要先清理一下您的图像以简化操作。尝试以下方法:

  1. opening(删除小的隔离组件)。 Result
  2. closing(重新连接关闭的组件)。 Result
  3. (可选)连接组件标签以便将每个字母分开(以后肯定需要它)
  4. 然后,您可以使用直方图投影,这将更容易分析。您应该在信号中看到尽可能多的峰值。
  5. (可选)如果直方图不够干净,请使用中值滤波器和高斯滤波器,以便对信号进行去噪和平滑。
相关问题