# Pixel transformation or remapping into new matrix and coordinates?

17 Ansichten (letzte 30 Tage)
Imran Riaz am 12 Aug. 2022
Beantwortet: Udit06 am 17 Nov. 2023
I need solution of my following problem. I have also attached an image for explanation.
Pixel transformation or remapping into new matrix and coordinates
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Chris am 9 Sep. 2022
That image is difficult to read, but would imwarp help?

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

Udit06 am 17 Nov. 2023
Hi Imran,
I understand that you want to map the non-black pixels of your image to new coordinates. You can follow the following steps to do the same:
1. Find non-zero pixel coordinates in the image.
2. Define the transformation function that takes the row and column indices as inputs and returns the new row and column indices. Apply this transformation function to each non-zero pixel coordinate.
3. Initialize a new image with the same size as the original image and set all pixels to black (zero values). Assign the non-zero pixel values from the original image to the new coordinates in the new image.
Following is the code implementation of the steps suggested above.
% Reading the image with a given filePath
% Find Non-Zero Pixel Coordinates
[row, col] = find(image ~= 0);
% Map Pixel Coordinates to New Coordinates where t is the transformation function
[new_row, new_col] = t(row, col);
% Create a New Image with Mapped Pixel Values
new_image = zeros(size(image));
num_nonzero_pixels = numel(row);
for i = 1:num_nonzero_pixels
new_image(new_row(i), new_col(i)) = image(row(i), col(i));
end
new_image=uint8(new_image);
% Display the New Image
imshow(new_image);
I hope this helps.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Geometric Transformation and Image Registration finden Sie in Help Center und File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by