【问题标题】:How do I use flipdim to flip the red and green channels in an image?如何使用 Flipdim 翻转图像中的红色和绿色通道?
【发布时间】:2015-12-29 02:20:00
【问题描述】:

我在 MATLAB 中使用 flipdim 命令的项目遇到问题。我需要用它来翻转 RGB 图像的红色和绿色。我设法用flipdim(e,3); 翻转了红色和蓝色,但不知道如何解决这个问题。有人可以帮忙吗?

这是我目前的代码:

%call an image
d=uigetfile('*.jpg','choose an image file');
%read an image ito an array
e=imread(d);
%define plot 1
subplot(1,2,1)
%show image original image
imshow(e)
%hold figure 
hold
%rotate original image 90 degreesR
l=flip(e(:,:,1:2),3);
%define plot 2
subplot(1,2,2)
%show altered image
imshow(l)

【问题讨论】:

  • 我需要使用 Flipdim 来做这个

标签: image matlab image-processing rgb


【解决方案1】:

执行flipdim(e,3) 将反转所有通道,所以这就是为什么红色和蓝色被翻转而绿色保持不变......这是有道理的,因为如果红色是第一个切片,绿色是第二个,蓝色是第三个,翻转它会使蓝色为第一个,绿色为第二个,红色为第三个。

如果您只想翻转红色和绿色通道并仅使用flipdim,请按照您的说明在第三维中使用flipdim,但仅适用于前两个通道。假设e 是原始图像,则创建一个新图像......像在您的代码中一样将其命名为l,然后将flipdim 应用于这个新图像的前两个通道:

l = e;
l(:,:,1:2) = flipdim(l(:,:,1:2), 3);

...但是,根本不需要使用flipdim...我会很聪明地索引到第三维:

l = e(:,:,[2 1 3]);

这可以有效地按照您想要的正确顺序排列红色和绿色通道。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-22
    • 2017-11-28
    • 1970-01-01
    • 1970-01-01
    • 2022-12-06
    • 1970-01-01
    • 2011-10-28
    • 1970-01-01
    相关资源
    最近更新 更多