how to calculate image prediction ?
3 views (last 30 days)
Show older comments
i was asked to calculate correlation between pixels
and then to claculate the prediction of image with this hint :
e(i,j)=img(i,j)- img(i,j-l) if i=0
e(i,j)=img(i,j)-img(i-l,j) if j=0
and then the correlation of this image
anyone can help me please !!,
0 Comments
Answers (1)
Deepak
on 17 Oct 2024
Hi Narimen,
As I understand it, you want to calculate the prediction error image “e (i,j)” of the input image, based on the given hint formulas. You also want to calculate the correlation of this image based on the prediction error image.
To accomplish this task, we can load the input image in MATLAB and convert it to grayscale and double format using the “rgb2gray” and “double” functions for accurate calculations. Next, we can iterate over the rows and columns of the image using nested for loops to calculate the prediction error image. Finally, we can calculate the correlation of the image by using the “corrcoef” function in MATLAB.
Below is the complete MATLAB code to accomplish this task:
img = imread('your_image.jpg');
img = double(rgb2gray(img)); % Convert to grayscale and double for calculations
[rows, cols] = size(img);
% Initialize the prediction error image
e = zeros(rows, cols);
for i = 1:rows
for j = 1:cols
if i == 1 && j > 1
e(i, j) = img(i, j) - img(i, j-1); % Use the previous pixel in the row
elseif j == 1 && i > 1
e(i, j) = img(i, j) - img(i-1, j); % Use the previous pixel in the column
elseif i > 1 && j > 1
% For other pixels, you can choose one of the predictions or a combination
e(i, j) = img(i, j) - img(i-1, j);
end
end
end
% correlation of the prediction error image
correlation = corrcoef(e(:));
disp('Correlation of the prediction error image:');
disp(correlation);
Please find attached documentation of functions used for reference:
I hope this assists in resolving the issue.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!