完整细分代码:
% Preprocessing + Segmentation
% // Original Code of Segmentation by Soumyadeep Sinha with several modification by Ana//
% Saving each single segmented character as one file
function [s] = seg (a)
myFolder = 'D:\1. Thesis FINISH!!!\Simulasi I\Segmented Images';
% a = imread ('adv1.png');
% Binarization %
level = graythresh (a);
b = im2bw (a, level);
% Complement %
c = imcomplement (b);
% Morphological Operation - Dilation %
se = strel ('square', 1);
% se = strel('rectangle', [1 2]);
r = imerode(c, se);
i=padarray(r,[0 10]);
% i=padarray(c,[0 10]);
% Morphological Operation - Dilation %
% se = strel('rectangle', [1 2]);
% se = strel ('square', 1);
% i = imerode(r, se);
%VP
verticalProjection = sum(i, 1);
set(gcf, 'Name', 'Segmentation Trial', '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));
% im = subImage;
s = subImage;
% figure, imshow (s);
% Normalization %
[p] = normalization (s);
% se = strel ('square', 1);
% se = strel('rectangle', [2 1]);
% im = imdilate(p, se);
% Morphological Operation - Thinning %
im = bwmorph(p,'thin',Inf);
% Save %
[L,num] = bwlabel(im);
for z= 1 : num
bw= ismember( L, z);
% Construct filename for this particular image.
baseFileName = sprintf('data.%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(1);
imshow(bw);
end
% y=y+1;
end;
s = (im);
单词图片
最近,我是手动完成的,但是数据集会更大,因此浪费时间来逐个运行分割图像。 有什么建议,我该怎么办才能让它简单有效?获取每个分段字符的结果(按顺序)。
% Save %
[L,num] = bwlabel(im);
for z= 1 : num
bw= ismember( L, z);
% Construct filename for this particular image.
% Change basefilename for each word images %
baseFileName = sprintf('data (1).%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(1);
imshow(bw);end
使用此代码后,它会创建一个好的结果,但只有一个数据,下一个数据将替换最近的数据。因此,最近,对于每个单词图像,我逐个运行分割过程并更改此部分以获得适当的结果。将sprintf(&#39; data(1)。%d.png&#39;,y)更改为sprintf(&#39; data(2)。%d.png&#39;,y);等等。
% Change basefilename for each word images %
baseFileName = sprintf('data (1).%d.png', y);
y=y+1;
任何帮助将非常感谢。
答案 0 :(得分:1)
由于阿拉伯语是我的母语,我会帮助你。 首先我要说清楚:一些阿拉伯字母包含非连接区域。 因为这种使用图像处理技术是不够的。 几年前,我设计了一个利用这个想法的系统:与同一个字母相关的区域在字母的上方或下方。 步骤:
如果文字由人们“手写”写成,问题就会变得更加复杂。 然后,您需要一个机器学习解决方案来验证分段区域。