使用Matlab翻转图像

使用Matlab翻转图像

本文介绍了使用Matlab翻转图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经熟悉了名为"MATLAB"的软件,并且拥有名为"flipLtRt.m"的文件,其中包含以下代码:

I am familiarizing myself with the software called 'MATLAB' and I have the file called 'flipLtRt.m' with following code:

function newIm = flipLtRt(im)
% newIm is impage im flipped from left to right

[nr,nc,np]= size(im);    % dimensions of im
newIm= zeros(nr,nc,np);  % initialize newIm with zeros
newIm= uint8(newIm);     % Matlab uses unsigned 8-bit int for color values


for r= 1:nr
    for c= 1:nc
        for p= 1:np
            newIm(r,c,p)= im(r,nc-c+1,p);
        end
    end
end

通过应用以下代码:

I = imread('Dog.jpg');
Dog = flipLtRt(I);
imshow(Dog);

我的狗图像被镜像.

我们很容易使用此文件'flipLtRt.m'镜像图像而无需实际理解代码.如果有人告诉我镜像图像,我可以简单地应用代码(第二部分),但是如果有人告诉我实际解释每一行代码是如何做的,我将无能为力.

It is easy for us to use this file 'flipLtRt.m' to mirror an image without actually understanding the code. If someone tells me to mirror an image, I can simply apply the code (second section) but if someone tells me to actually explain how each line of code do, I won't be able to.

任何人都可以解释代码的每一行实际做什么吗?
这是我无法正确理解的"for"部分.什么是"np"?新职位?

Would anyone be able to explain what each line of the code actually do?
It's the 'for' part that I cannot understand properly. And what is 'np'? New position?

推荐答案

代码遍历图像 im 的行,该图像由具有 nr 的矩阵表示行和 np 列,翻转:

The code iterate over the rows of the image im, which is represented by a matrix with nr rows and np columns, flipping:

  • 最后一列为第一列;
  • 倒数第二个第二列;
  • 第c列和第nc-(c-1)列;

您会看到此列在行上翻转:

You can see this column flipping at the line:

newIm(r,c,p)= im(r,nc-c+1,p);

位置:

  • r 是行索引, nr 是行数;
  • c 是列索引 nc 是列数;
  • p 是颜色通道索引(例如:1 =红色,2 =绿色,3 =蓝色);
  • np 是颜色通道的数量;
  • r is the row index, nr is the number of rows;
  • c is the column index nc is the number of columns;
  • p is color channel index (e.g.: 1=Red, 2=Green, 3=Blue);
  • np is the number of color channels;

这篇关于使用Matlab翻转图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 20:58