【问题标题】:Fusion of two images in matlabmatlab中两幅图像的融合
【发布时间】:2014-12-09 11:37:21
【问题描述】:

考虑两个图像。这两个图像的大小可以是任何值。使这两个图像的大小相同。开发一种算法来混合这两个图像,以便从两个图像过程中获得交替像素。它是两个图像的融合。例如,像素 1 是图像 1 的像素,像素 2 来自图像 2,图像 1 的第 3 个像素等等……

【问题讨论】:

  • 你为什么要这样做?

标签: image matlab pixel mixing


【解决方案1】:

我知道你更喜欢使用 Matlab,但在有人给你 Matlab 答案之前,你可能会喜欢使用 ImageMagick,它可以为你做到这一点,并且无论如何都在大多数 Linux 发行版中,并且可免费用于 Windows 和 Mac OSX .

首先,让我们创建 2 张不同大小和颜色的图像:

convert -size 300x300 xc:blue image1.png
convert -size 200x400 xc:red  image2.png

基本上,您可以通过在文件名后面的方括号中指定图像大小来调整读取图像的大小,因此我任意选择将两个图像的大小调整为 256x256 像素。然后我使用极其强大的fx 运算符,因此检测我是在处理奇数还是偶数像素,并相应地从第一张或第二张图像中进行选择:

convert image1.png[256x256] image2.png[256x256] -fx "i%2?u:v" out.png

【讨论】:

    【解决方案2】:

    这是使用 MATLAB 的一种方法。

    clear
    clc
    
    %// Initialize red and blueimages
    RedImage = zeros(300,300,3,'uint8');
    BlueImage = zeros(200,400,3,'uint8');
    
    %// Color them
    RedImage(:,:,1) = 255;
    BlueImage(:,:,3) = 255;
    
    figure('Color',[1 1 1]);
    
    %// Show them
    subplot(1,2,1)
    imshow(RedImage)
    subplot(1,2,2)
    imshow(BlueImage)
    

    看起来像这样:

    %// Resize them to same size
    RedImage = imresize(RedImage,[256 256]);
    BlueImage = imresize(BlueImage,[256 256]);
    
    %// Initialize new image
    NewImage = zeros(256,256,3,'uint8');
    
    %// Assign alternate pixels to new images
    NewImage(1:2:end,1:2:end,:) = RedImage(1:2:end,1:2:end,:);
    NewImage(2:2:end,2:2:end,:) = BlueImage(2:2:end,2:2:end,:);
    
    figure
    imshow(NewImage)
    

    哪个输出这个:

    它看起来很暗,但调整图形大小会告诉你它确实有效!

    希望对您有所帮助!玩得开心。

    【讨论】:

      猜你喜欢
      • 2014-07-04
      • 2011-09-15
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多