Pixel Back mapping from Output to input using Grid like structures

3 次查看(过去 30 天)
Hi,
Am trying to map the pixel on the output to input using multiple grids. Lets say my output image size is of 100*100. I want to create a grid for my output image, where are certain locations of the grid lets say 25*25 pixels is mapped from image 1 and another 35*25 mapped from image 2,.. and so on. So the output image is a blend of different images merged together in different proportions. Why mesh? Because i want to manually choose which portion of the image (ROI) is sent to the output image from each input specifically. Is there a way to involve mesh in this selection process?

回答(1 个)

Divyam
Divyam 2024-9-18
The "meshgrid" function can be used to define the mesh grid for the output images and the regions of interests in the input images. After defining the appropriate regions of interests in the ouput and input images, corresponding regions from input images can be mapped to the output image by using the "sub2ind" function for converting the array subscripts to linear indexes which can be used to access the correct image pixels.
% Define the size of the output image
outputSize = [100, 100];
outputImage = zeros(outputSize(1), outputSize(2), 3, 'uint8');
% Load the input images and define more images as needed
image1 = imread('image1.jpg');
image2 = imread('image2.jpg');
% Define the mesh grid for the output image
[xOut, yOut] = meshgrid(1:outputSize(2), 1:outputSize(1));
% Define the regions in the output image using mesh
% Map a 25x25 region from image1 and a 35x25 region from image2
% Define the ROIs in the output image
roi1_output = (xOut >= 1 & xOut <= 25) & (yOut >= 1 & yOut <= 25);
roi2_output = (xOut >= 26 & xOut <= 60) & (yOut >= 1 & yOut <= 25);
% Define the corresponding ROIs in the input images using mesh
[xIn1, yIn1] = meshgrid(10:34, 10:34);
[xIn2, yIn2] = meshgrid(50:84, 50:74);
% Map the regions from input images to the output image
outputImage(roi1_output) = image1(sub2ind(size(image1), yIn1, xIn1));
outputImage(roi2_output) = image2(sub2ind(size(image2), yIn2, xIn2));
% Display the output image
imshow(outputImage);
For more information regarding the "meshgrid" and "sub2ind" functions, refer to the following documentation links:

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by