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