二维图像像素转换

2D Image transformations by pixel

我正在尝试对图像逐像素进行平移、欧几里得、相似性、仿射和投影变换。我程序的输入是图像名称和转换矩阵。

这是我的代码

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

这是图片

现在我只测试一个翻译矩阵。

matrix = 

     1     0     7
     0     1     2
     0     0     1

当我通过函数传递图像和矩阵时,我的结果只是一条小黑线

我做错了什么?

使用 matlab 调试器,我注意到您正在强制转换为 int8,它太小了,无法代表所有索引。因此,您应该使用 int32/int64uint32/uint64,即

answer = uint8(answer);

应该是

answer = uint32(answer);

提问前请先尝试使用Matlab调试器:为什么不行?