【问题标题】:Interpolation algorithm all values 255 -MATLAB插值算法所有值 255 -MATLAB
【发布时间】:2019-04-03 22:59:53
【问题描述】:

我试图在 Matlab 中创建自己的最近邻插值算法,以将 556×612 的图像放大到 1668×1836。

这是作业!!!

我已经尝试过了,但遇到了错误,其中 M 中的值(不是全部,而是大部分)转换为 255(空白),我无法理解为什么。任何帮助,将不胜感激!图片是斑马的图片。

    %Take in image and convert to greyscale
I = imread('Zebra.jpg');
Igray = rgb2gray(I);

% Step-3: Resize the image to enlarged 1668x1836 by interpolation
% Step-3(a) : Using nearest neighbour
%First we will need to work out the dimension of the image
[j , k] = size(Igray);
%Now we need to set the size of the image we want
NewX = 1836;
NewY = 1668;
% Work out ratio of old to new
ScaleX = NewX./(j-1);
ScaleY = NewY./(k-1);

%Image Buffer
M = zeros(NewX, NewY);
%Create output image
for count1 = 1:NewX
    for count2 = 1:NewY
        M(count1,count2) = Igray(1+round(count1./ScaleX),1+round(count2./ScaleY));
    end
end
%Show Images
imshow(M);
title('Scaled Image NN');

【问题讨论】:

  • 哦,我不能使用任何内置的matlab函数!

标签: matlab interpolation nearest-neighbor


【解决方案1】:

试试imshow(M,[])。您在没有指定类型的情况下创建了 M,这使其成为 doubledouble 图像为 [0-1],因此 imshow 默认情况下会将值高于 1 的所有内容设为白色。

或者,将M 创建为uint8 作为原始图像

M = zeros(NewX, NewY,'uint8');

更好的代码是:

M = zeros(NewX, NewY,class(Igray));

【讨论】:

    猜你喜欢
    • 2010-12-05
    • 1970-01-01
    • 1970-01-01
    • 2018-01-14
    • 1970-01-01
    • 2017-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多