MATLAB - 从文件中翻译彩色图像

时间:2015-12-09 10:28:27

标签: matlab plot png

我有一个彩色PNG图像,我需要翻译它并绘制结果,它应该与原始图像具有相同的色标。使用下面的代码,我得到一个灰度图像;你知道怎么解决这个问题吗?谢谢!

[E_col, map_E] = imread('E.png');
shift_vert = 35; % 152
shift_hor = 30;
E_col_shift = zeros(size(E_col,1) + shift_vert, size(E_col,2) + shift_hor);
E_col_shift = imtranslate(E_col_shift,[shift_hor, shift_vert]);
figure; imshow(E_col_shift, map_E);

在这里,您可以找到我正在使用的图片:enter image description here

1 个答案:

答案 0 :(得分:1)

你有一个典型的错误:

% // This image is JUST ZEROES!!!!!!!!!!!!!!!!!!!!!!!!!!
E_col_shift = zeros(size(E_col,1) + shift_vert, size(E_col,2) + shift_hor);


%// So why are you translating the empthy image?!?!?!
E_col_shift = imtranslate(E_col_shift,[shift_hor, shift_vert]);

%// It should be the original image!!!!!
E_col_shift = imtranslate(E_col,[shift_hor, shift_vert]);