2016-07-22 1 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 '경로).

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

이 당신이 후했다 물건의 종류

%%%% 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' %%%% 

그런 다음에 전화?

+0

참고 : 위의 코드는 옥타브와 호환되지만, –

+0

(알파벳 이미지는 다음에서 변환 : http://www.joaoleitao.com/names-arabic/arabic-alphabet-abc/) –

+1

I 이미지 패키지를 먼저로드하십시오. MATLAB 액츄에이터 사용 동맹국. || 제공해 주신 코드를 보내 주셔서 감사합니다. 나는 시도 할 것이다. –

관련 문제