1D projection of image and cross correlation

8 views (last 30 days)
I would like to project a image in 1D and take a flipped version of it and take the cross correlation . how can I plot the 1D profille and the flipped image overlayed and the crosscorelation in matlab

Answers (1)

Gokul Nath S J
Gokul Nath S J on 26 May 2023
Hi Vivek,
To plot the 1D profile and the flipped image overlaid with the cross-correlation plot in MATLAB, you can use the plot function to plot the 1D profile and flipped image, and the xcorr function to compute the cross-correlation. Here's an example code that shows how to do this:
% Load the image to be flipped and cross-correlated
img = imread('sample_image.png');
% Convert the image to grayscale and resize to a 1D vector
img_gray = rgb2gray(img);
img_vector = double(img_gray(:));
% Flip the image vector
img_flipped = flip(img_vector);
% Compute the cross-correlation between the original and flipped images
[r,lags] = xcorr(img_vector, img_flipped);
% Plot the 1D profile and flipped image overlaid
figure;
plot(1:length(img_vector), img_vector, 'b');
hold on;
plot(1:length(img_flipped), img_flipped, 'r');
legend('Original Image', 'Flipped Image');
xlabel('Pixel Position');
ylabel('Intensity');
title('Original and Flipped Images');
% Plot the cross-correlation
figure;
plot(lags, r);
xlabel('Lag');
ylabel('Cross-Correlation Coefficient');
title('Cross-Correlation between Original and Flipped Images');
with regards,
Gokul Nath S J

Categories

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

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!