2016-07-22 13 views
-1

私はすでにpadarray(以下のコード)を使って正規化を行っていますが、次の処理(特徴抽出)の結果は十分ではありません。セグメント化されたパーツフィーチャではなく、パッドパーツを含むためです。分割された文字画像のサイズ正規化

enter image description here -sample画像(セグメント化された文字)

は、私は、画像のみセグメント化された文字を正規化することが中心に置く必要がある、との二乗(それがすることになって[64 64])。また、画像を伸ばしたり歪ませたりせずにアスペクト比を保持する必要があるため、文字画像は比例した状態に保たれます。

% Normalization done using pad 
function p = pad (im) 
nrows = size(im,1); 
ncols = size(im,2); 

d = abs(ncols-nrows); % difference between ncols and nrows: 
if(mod(d,2) == 1)  % if difference is an odd number 
    if (ncols > nrows) % we add a row at the end 
     im = [im; zeros(1, ncols)]; 
     nrows = nrows + 1; 
    else     % we add a col at the end 
     im = [im zeros(nrows, 1)]; 
     ncols = ncols + 1; 
    end 
end 

if ncols > nrows 
    im = padarray(im, [(ncols-nrows)/2 0]); 
else 
    im = padarray(im, [0 (nrows-ncols)/2]); 
end 

im = imresize(im, [64 64]); 

% figure, imshow (im); 

p = (im); 

% Here im is a 5x5 matix, not perfectly centered 
% because we added an odd number of columns: 3 
% Original code by Sembei Norimaki, modified by Ana 

このコードの一部の変更は、まだ動作しません。だから、私はこのコードの変更やこの場合に推奨される方法の提案が必要です。

ご協力いただければ幸いです。ありがとうございました。

+0

あなたが正確に何をしようとしているのかはまだ分かりません。画像をトリミングして、64x64のゼロ配列の中心にコピーしようとしていますか?あなたの画像はすべて64x64未満であることが保証されていますか? –

+0

ゼロ配列にコピーするとどういう意味ですか?もっと説明できますか? ||私はアスペクト比を維持したまま、すべての画像を[64 64]に正規化(サイズ変更)する必要があります。 ||サイズは様々ですが、64x64より小さくて大きくなります。私は "imresize"を使うことができましたが、画像が歪んだり伸びたりすると、不均衡な結果が出ます。 ||提案はありますか?応答してくれてありがとう。 –

+1

イメージ引数とスカラー(2要素ベクトルとは対照的に)だけをとる 'imresize'を使うと、アスペクト比は変わらないでしょう。あなたはアスペクト比だけを気にしますか、または文字をお互いに正しいサイズにしたいですか? (あなたの例では、「パーツ」はボックスを埋めるわけではありません)それは意図的なのですか? –

答えて

1

それはあなたが後にしているものだが、ここに行く100%わからない:

例:(画像 'alif.png'、 'dod.png'、 'ha.png'、および「UAUを前提としています。パス内の「png」)。その後

%%%% in file 'processLetter.m' %%%% 
function L = processLetter (L) 
    %% Step 1 : Trim padding. 
    tmp = find (L); % Get linear indices of nonzero elements 
    [Row_subs, Col_subs] = ind2sub (size (L), tmp); % Convert to row/col subscripts 
    L = L(min (Row_subs) : max (Row_subs), min (Col_subs) : max (Col_subs)); % trim 

    %% Resize such that the largest dimension is scaled to 64 pixels 
    Rows = size (L, 1); Cols = size (L, 2); 
    if Rows > Cols; Resize_vec = [64, NaN]; 
    else   Resize_vec = [NaN, 64]; 
    end 

    L = imresize (L, Resize_vec); 
    Rows = size (L, 1); Cols = size (L, 2); 

    %% Pad smallest dimension to 64 pixels 
    if Rows > Cols; 
    LeftPad = abs (floor ((64 - Cols)/2)); 
    RightPad = abs (floor ((Cols - 64)/2)); 
    L = padarray (L, [0, LeftPad ], 'pre'); 
    L = padarray (L, [0, RightPad], 'post'); 
    else 
    TopPad = abs (floor ((64 - Rows)/2)); 
    BottomPad = abs (floor ((Rows - 64)/2)); 
    L = padarray (L, [TopPad, 0], 'pre'); 
    L = padarray (L, [BottomPad, 0], 'post'); 
    end 

    L = mat2gray (L); 
    L = L > 0.5; % in case L was a 'double' matrix -- needed in Octave 
end 
%%%% end of file 'processLetter.m' %%%% 

を呼び出す:

Alif = imread ('alif.png'); Dod = imread ('dod.png'); 
Ha = imread ('ha.png' ); Uau = imread ('uau.png'); 
Alif = double (Alif); Dod = double (Dod); Ha = double (Ha); Uau = double (Uau); % if using octave -- octave 'imresize' function throws an error if image is logical instead of double 
subplot (2, 4, 1); imagesc (Alif); axis equal off; colormap gray; 
subplot (2, 4, 2); imagesc (Dod); axis equal off; 
subplot (2, 4, 3); imagesc (Ha ); axis equal off; 
subplot (2, 4, 4); imagesc (Uau); axis equal off; 
subplot (2, 4, 5); imagesc (processLetter (Alif)); axis equal off; 
subplot (2, 4, 6); imagesc (processLetter (Dod)); axis equal off; 
subplot (2, 4, 7); imagesc (processLetter (Ha) ); axis equal off; 
subplot (2, 4, 8); imagesc (processLetter (Uau)); axis equal off; 

結果:

enter image description here

これはあなたが後にしたもののようなものですか?

+0

注:上記のコードはOctave互換ですが、 –

+0

(アルファベットの画像は、ここから変換されています:http://www.joaoleitao.com/names-arabic/arabic-alphabet-abc/) –

+1

私は、 'image'パッケージを最初に明示的に読み込みます。 matlabの操作を使用しています同盟国。 ||あなたが提供したコードをありがとう。私が試してみます。 –

関連する問題