How to move pixels to a new coordinate by a function?
4 次查看(过去 30 天)
显示 更早的评论
I'm not very experienced with matlab yet and have the following problem: I would like to take any picture and use it as the domain of a complex function. That means, I have a picture in a coordinate system with a number of x and y values and I can move a pixel that corresponds to a x,y value to it's new place, for example to (real(f),imag(f)). My problem is that I can't figure out how to determine the position of a pixel and how to set it to a new position value.
0 个评论
采纳的回答
Duncan Lilley
2017-12-11
Hello,
After an image is read into MATLAB, it is stored as a matrix of numbers. These numbers determine the color of the pixel corresponding to that index. Different kinds of images are stored differently. For example, grayscale images may be stored as an NxM matrix whereas color images can be stored as an NxMx3, since values are needed for each the red, green, and blue components.
To move a pixel, you need to copy the values from one index to another. Consider the following example of swapping two pixels in an image:
% Want to swap pixel at (x1,y1) in image with the pixel at (x2,y2)
I = imread('face.jpg');
x1 = 25;
y1 = 25;
x2 = 25;
y2 = 370;
% Get pixel data from image
pixel1 = I(y1, x1, :);
pixel2 = I(y2, x2, :);
% Swap pixels
I(y1, x1, :) = pixel2;
I(y2, x2, :) = pixel1;
imshow(I);
In your use case, it appears that you will be determining the pixel coordinate from the real and imaginary components of complex numbers.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!