How do i map mu euclidean distances calulcated in order to create stack to make image foveated

1 次查看(过去 30 天)
%image files
i1 = imread("iron-man-marvel-chrome-theme-wallpaper.png");
i2 = imread("iron-man-marvel-chrome-theme-wallpaper2.png");
i3 = imread("iron-man-marvel-chrome-theme-wallpaper3.png");
i4 = imread("iron-man-marvel-chrome-theme-wallpaper4.png");
i5 = imread("iron-man-marvel-chrome-theme-wallpaper5.png");
%concatened array full of images
m = cat(4,i1,i2,i3,i4,i5);
%check each rgb invidually
red = m(:,:,1);
green = m(:,:,2);
blue = m(:,:,3);
%create/update rgb stacks, rgb stacks will be 5
red = m(:,:,1,:);
green = m(:,:,2,:);
blue = m(:,:,3,:);
r = squeeze(red);
g = squeeze(green);
b = squeeze(blue);
red = m(:,:,1,1);
x1 = 306;
y1 = 404;
x = 1:353;
y = 1:483;
%Returns 2-D grid coordinates based on the coordinates contained in vectors x and y.
%X is a matrix where each row is a copy of x, & Y is a matrix where each column is a copy of y
[X,Y] = meshgrid(y,x);
distance = sqrt((X-x1).^2 + (Y-y1).^2);
I am trying to map my distance variable to image with highest resolution and basically create fixation points of when i focus on anothe rpoint within image based on distances from center origin, I want to apply all distance calulcated from center origin and make image fovaeated. output of the distance variable stores pixels and want to map those pixels to my image to make image foveated

回答(1 个)

Karan Singh
Karan Singh 2023-9-5
Hi Sanjit,
From what I understand, the code you provided loads five image files (i1, i2, i3, i4, and i5) into an array called m. Each image is represented as a 3D matrix, where the third dimension represents the RGB channels.
Next, you extracted the red, green, and blue channels from the m array and stored them separately in red,green, and blue variables. Then, you created/updated the RGB stacks by assigning the extracted channels back to red,green, and blue.
After that, you assigned the first image's red channel (m(:,:,1,1)) to the redvariable, and defined the coordinates (x1 and y1) for the center origin.
To create fixation points based on distances from the center origin, you calculated the Euclidean distance from the center origin to each pixel in the image using meshgrid. The resulting distance values are stored in the distancevariable.
To map the distance variable to an image and create a foveated effect, you can use the distance values as indices to select pixels from the image. 
Here's an example of how you can achieve this:
% Load the highest resolution image
highest_resolution_image = i5;
% Define the center origin coordinates
x1 = 306;
y1 = 404;
% Create a meshgrid for the image coordinates
[x, y] = size(highest_resolution_image(:,:,1));
[X, Y] = meshgrid(1:y, 1:x);
% Calculate the distance from the center origin
distance = sqrt((X - x1).^2 + (Y - y1).^2);
% Normalize the distance values between 0 and 1
normalized_distance = distance / max(distance(:));
% Apply the foveated effect by selecting pixels based on distance
foveated_image = highest_resolution_image;
for channel = 1:3
foveated_image(:,:,channel) = uint8(double(foveated_image(:,:,channel)) .* normalized_distance);
end
% Display the foveated image
imshow(foveated_image);
In this code, we load the highest resolution image (i5 in this case) and define its center origin coordinates (x1 and y1). We create a meshgrid for the image coordinates using the size of the image. Then, we calculate the distance from the center origin for each pixel using the meshgrid.
Next, we normalize the distance values between 0 and 1 to ensure they are within the valid range for pixel intensity. We apply the foveated effect by multiplying the pixel values of each channel by the normalized distance.
Finally, we display the resulting foveated image using imshow.
Attached below are some documentation links that you may find helpful:
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by