我在 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(e,3)
将反转所有 channel ,因此这就是红色和蓝色翻转而绿色保持不变的原因......使得这是有道理的,因为如果第一片是红色,第二片是绿色,第三片是蓝色,翻转就会使第一片变成蓝色,第二片变成绿色,第三片变成红色。
如果您只想翻转红色和绿色 channel 并仅使用 flipdim
,请按照您的说明在第三维中使用 flipdim
,但仅适用于前两个 channel 。假设 e
是原始图像,创建一个新图像...像在代码中一样将其称为 l
,然后将 flipdim
应用于第一个图像此新图像的两个 channel :
l = e;
l(:,:,1:2) = flipdim(l(:,:,1:2), 3);
...但是,根本不需要使用 flipdim
...我会很聪明地索引到第三个维度:
l = e(:,:,[2 1 3]);
这可以有效地按照您想要的正确顺序排列红色和绿色 channel 。
关于image - 如何使用 Flipdim 翻转图像中的红色和绿色 channel ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32880626/