完全なセグメンテーションコード:私は単語画像の文字セグメンテーション処理を行うためにMATLABワークスペースに画像をロードした保存セグメンテーション結果 - Matlabのアラビア語OCR
% 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);
- 。例:data(1).png、data(2).pngなど。
- セグメント化プロセスは、セグメント化された各文字の出力として複数のイメージを提供します。 Wordの画像にはさまざまな文字が含まれているため、出力も変わります。たとえば、image = data(1).pngのセグメント化された結果の出力は、データ(1)_1.png、data(1)_2.png、data(1)_3.png、およびdata(2) (2)_1.png、data(2)_2.pngなどです。
Wordの画像
最近、私は手動でそれをやったが、データセットが大きく、それはとても1枚の画像ずつのためのセグメンテーションを実行するために時間を無駄になります。 提案はありますか?それを簡単かつ効果的にするにはどうすればよいですか?セグメント化されたすべての文字の結果を(順番に)取得します。
% 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
このコードを使用した後は、良い結果が得られますが、1つのデータの場合のみ、次のデータが最新のデータに置き換えられます。だから、最近、すべての単語画像について、私はセグメント化プロセスを1つずつ実行し、この部分を変更して適切な結果を得ます。 sprintf( 'data(1)。%d.png'、y)をsprintf( 'data(2)。%d.png'、y)に変更します。等々。
% Change basefilename for each word images %
baseFileName = sprintf('data (1).%d.png', y);
y=y+1;
私が望む結果です。私はそれを自動的に得ることを願っています。
ご協力いただければ幸いです。
Sprintf( 'data(%d)。%d.png'、imageIdx、y = y + 1) – BH85
もしあなたが気にしないなら、 @ BH85 Sprintf( 'データ(%d)。%d.png'、imageIdx、y = y + 1)? –
フォルダxから画像を読み取っている場合:最初の手順はファイルの名前を取得することです。 2番目のステップでは、これらのファイルを1つずつ繰り返します。通常はforループを使用して繰り返します。このforループの変数はイメージインデックスです。 files_Info = dir( 'C:\ ...どこにあなたの画像がありますか? size(files_Info、1)は、このディレクトリ内のファイルの数です(削除する必要がある '。'と '..'を含みます)。 imageIdx = 1:size(files_Info、1)の場合、 ''ではないかどうかを確認します。または '..'。処理のステップへ行く..... ..... – BH85