How to move pixels to a new coordinate by a function?

14 views (last 30 days)
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.

Accepted Answer

Duncan Lilley
Duncan Lilley on 11 Dec 2017
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.

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!