2017-09-19 73 views
-1

我正在嘗試在像素上逐像素地對圖像進行平移,歐幾里得,相似度,仿射和投影轉換。我的程序的輸入是圖像名稱和變換矩陣。按像素進行2D圖像轉換

這是我的代碼

function imagetrans(name, m) 
Image = imread(name); 
[rows, cols] = size(Image); 

newImage(1:rows,1:cols) = 1; 

for row = 1 : rows 
    for col = 1 : cols 
     if(Image(row,col) == 0) 
      point = [row;col;1]; 
      answer = m * point; 
      answer = int8(answer); 
      newx = answer(1,1); 
      newy = answer(2,1); 

      newImage(newx,newy) = 0; 
     end 
    end 
end 

imshow(newImage); 

end 

這是圖像press here for image

現在我只測試一個平移矩陣。

matrix = 

    1  0  7 
    0  1  2 
    0  0  1 

,當我通過函數傳遞圖像和矩陣我的結果只是一個小的黑線press here to see pic

我在做什麼錯?

回答

0

使用matlab調試器,我注意到你正在鑄造到int8,這太小也代表所有指標。所以,你應該使用int32/int64uint32/uint64代替,即

answer = uint8(answer); 

應該

answer = uint32(answer); 

請試着問這個問題之前,使用Matlab的調試器:它爲什麼不工作?

+0

謝謝!我會嘗試這個,..我是新來的Matlab,我不知道有一個調試器。感謝您的更新 – Debbie

+0

這也工作!謝謝 – Debbie