2017-02-28 10 views
1

DICOMイメージを読みました。さまざまな理由から、イメージベクトルを行ベクトルに変換する必要がありました。 ベクトルのビットに対してさまざまな操作を実行した後、元のサイズと同じサイズのDICOMイメージでベクトルを再処理する必要があります。イメージからベクトルへ、またはその逆から、回転イメージ

私はこれらのすべてのステップを実行しましたが、結果のイメージを表示すると、これは回転されます。 これは私が得るものです: コードの一部ですenter image description here

function [I0, Iw] = watIns(filename, w)  
    I0 = dicomread(filename); 
    figure(1); 
    imshow(I0, []); 
    title('(1) I0 originale'); 

    info = dicominfo(filename); 
    width = info.Width; 
    height = info.Height; 
    size = info.FileSize; 
    k = info.BitDepth; 

    % I extract the first k pixels and memorize their LBS in a variable S. 
    x = 1 : k; 
    y = 1; 

    firstKPixel = I0(x, y); 

    % convert in binary 
    firstKPixel2 = 0*firstKPixel; 
    for i = 1 : length(firstKPixel) 
     if firstKPixel(i) == 0 
      firstKPixel2(i) = 0; 
     else 
      firstKPixel2(i) = dec2bin(firstKPixel(i), 'left-msb'); 
     end 
    end 


    % I take the LSB of each element in firstKPixel2 and concatenate in the string S 
    S = ''; 
    for i = 1 : k 
     c = firstKPixel2(i, :); 
     s = num2str(c(end)); 
     S = strcat(S, s); 
    end 

    % I compute the vector corresponding to I0 but without the first 0 pixels and the corresponding histogram 
    [vecComp, histComp] = histKtoEnd(I0, 0, k); 

    % I compute the vector corresponding to I0 but without the first k pixels and the corresponding histogram 
    [vecWithoutKPixel, histWithoutKPixel] = histKtoEnd(I0, k, k); 

    L = ...; % is a vector of values  

    % I save l_0 in the LSB of the first k pixels. 

    % prendo l_0, ovvero il primo elemento di L 
    l_0 = L(1); 

    l_02 = fliplr(bitget(l_0, 1:k)); 

    % I take the LSB of each element in firstKPixel2 and I sret it to the i-th element of l0_2 
    for i = 1 : k 
     c = firstKPixel2(i, :); 
     c(end) = l_02(i); 
     firstKPixel2(i, :) = c; 
    end 

    % convert to decimal each element of firstKPixel2 
    for i = 1 : length(firstKPixel2) 
     str = int2str(firstKPixel2(i)); 
     firstKPixel2_lsb10(i) = bin2dec(str); 
    end 

    % I set first k pixels in the image to those just modified 
    vecComp(1 : k) = firstKPixel2_lsb10(1 : k); 

    % Transform the vector image 
    mat = reshape(vecComp, [width, height]); 
    dicomwrite(mat, './I1.dcm', 'CompressionMode', 'None'); 
    I1 = dicomread('./I1.dcm'); 
    figure(7); 
    imshow(I1, []); % ROTATE IMAGE!!! 

    % ...  
end 

histKtoEnd機能は次のとおりです。私はhereを読ん

function [vecWithoutKPixel, hist] = histKtoEnd(image, k, colorDepth) 

    imageVec = reshape(image.', [], 1); 
    l = length(imageVec); 

    vecWithoutKPixel = imageVec((k+1) : l-1); 
    vecWithoutKPixel(end+1) = imageVec(l); 

    hist = zeros(1, 2^colorDepth); 

    for i = 0 : (2^colorDepth - 1) 
     grayI = (vecWithoutKPixel == i); 
     hist(1, i+1) = sum(grayI(:)); 
    end 

end 

MATLABは最初の行列のような画像を示します座標(行)はトップダウン、第2列(列)は左右に移動します。

私は解決できませんでした、誰も助けてくれますか? ありがとうございました!

+2

により、最終的に結果を転置することができます) ';' –

+0

@AnderBiguriありがとう、完璧に動作します。それが意味することは? – beth

+2

[** '.'' **は**' transpose' **](https://www.mathworks.com/help/matlab/ref/transpose.html)です。 –

答えて

4

どういうわけか、データを展開して処理してローリングすると、転記されたようです。 vecComp、[幅、高さ](あなたはそれが起こる理由を見つけることを試みることができますが、気にしないならば、あなたはいつもちょうどちょうど作り直す= `マットにコードを変更

mat = reshape(vecComp, [width, height]).'; 
関連する問題