【问题标题】:Image upsampling in MATLAB producing white images using image() and imshow()MATLAB 中的图像上采样使用 image() 和 imshow() 生成白色图像
【发布时间】:2013-09-27 02:17:13
【问题描述】:

当我显示我重建的图像时,它们只是白色的。我的程序有明显的问题吗?

重建的图像应该在上采样的2x2 像素块中的一个像素处具有下采样图像的值。我在这里使用的插值方法只是从上面的一行中获取值并用它填充下一行,对列重复此过程。

%% Image Resampling

close all; clear all; clc;

s_dir=pwd;
cd Images;

I=imread('aivazovsky78g.tif','tif');

cd(s_dir)

[N M]=size(I);

figure;
imshow(I)
axis image; hold on;

 for k=1:4
     pause(1)
     I=I(1:2:N, 1:2:M);
     [N M]=size(I);
     image(I)
 end

 %% Image Reconstruction

Irec=zeros(2*size(I));
for r=1:5
for n=1:N-1
    for m=1:M-1
        Irec(2*n-1,2*m-1)=I(n,m);
    end
end
[N M]=size(Irec);
for n=2:2:N
    for m=2:2:M
    Irec(n,:)=Irec(n-1,:);
    Irec(:,m)=Irec(:,m-1);
    end
end
I=Irec;
figure;
imshow(I)
 end

【问题讨论】:

    标签: image algorithm matlab image-processing resampling


    【解决方案1】:

    您可以使用B = imresize(A, scale, 'box'),其中scale 为2 会使xy 中的像素数量翻倍。 z 维度仍将具有相同的值。

    调整大小方法box 会将初始像素值(i, j) 复制到其3 个新邻居(i+1, j)(i, j+1)(i, j+1)(i+1, j+1) - 与您编程的方法相同。

    【讨论】:

      【解决方案2】:

      不是最有效的方法,但这是一个有效的代码:

      % 256x256 grayscale image
      I = imread('cameraman.tif');
      
      % double in size
      I2 = zeros(2*size(I),class(I));
      for i=1:2:size(I2,1)
          for j=1:2:size(I2,2)
              I2([i i+1],[j j+1]) = I((i-1)/2 + 1, (j-1)/2 + 1);
          end
      end
      
      % compare against @Magla's solution
      I3 = imresize(I,2,'box');
      isequal(I2,I3)
      

      【讨论】:

        猜你喜欢
        • 2014-04-21
        • 2021-12-17
        • 2013-11-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多