0
分割代码:分割,读字图像从右到左
% // Original Code by Soumyadeep Sinha
% Modified by Ana with several modification //
% Saving each single segmented character as one file
function [s] = seg (a)
myFolder = 'D:\1. Thesis FINISH!!!\Data set\trial';
% a = imread ('adv1.png');
% Binarization %
level = graythresh (a);
bw = im2bw (a, level);
% Complement %
b = imcomplement (bw);
% Morphological Operation - Dilation %
% se = strel('rectangle', [1 2]);
% r = imdilate(b, se);
r=padarray(b,[0 10]);
% % Morphological Operation - Dilation %
se = strel('rectangle', [1 2]);
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] = pad (s);
% 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('word6a.%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);
我已经做了分割为孤立字符做OCR。它运行良好, 但是,我希望分割的输出顺序不是从左到右,而是从右到左,就像我们读阿拉伯文字一样。
如果一切正常,将被保存为word6.1.png,保存为word6.2.png,其余保存为word6.3.png
我不知道该怎么做代码,使其从右向左阅读单词。
任何帮助将不胜感激。
是否可以将输入从左向右翻转例如使用'fliplr',从左到右运行算法,然后再次翻转输出? – mikkola