# How can I subtract the absolute value of the original image from the absolute value of the resized image to compare and to find the error in Matlab

3 visualizaciones (últimos 30 días)
GHADAH AL-OBAIDI el 5 de Jun. de 2021
Comentada: Image Analyst el 5 de Jun. de 2021
How can I subtract the absolute value of the original image from the absolute value of the resized image to compare and to find the error in Matlab.
The Matlab keeps giving me that both images have different sizes.
My code as below:
% Check the resized image against the original image then find and display the error
in1=imresize(i,0.5,'nearest'); % Resize the image by 1/2
i_diff=imabsdiff(i,in1);
figure;
imshow(i_diff);
title('Comparison between the resized image and the original image');
##### 3 comentariosMostrar 1 comentario más antiguoOcultar 1 comentario más antiguo
GHADAH AL-OBAIDI el 5 de Jun. de 2021
My image size is (436x500x3 uint8) pixels and I reduced the size of the image to (218x250x3 uint8) pixels. So as a result I lost half of the image.
Then I want to go back to (436x500x3 uint8) to recover the orginal image so I need to fill those lost pixels and also I want to compare the modified image with the orginal image that I started with to find the error and display it.
How can I do that in Matlab?
Amit el 5 de Jun. de 2021
Editada: Image Analyst el 5 de Jun. de 2021
1. First of all you need to check dimensions of both images by checking it with function size().
2. If sizes of both the images are not same then you can use resize function to make size of one image same as that of other image.
3. Then you can convert both the images from 'uint8' datatype to 'double' data type.
4. Then you need to find pixel to pixel difference between these to images and take absolute of difference value.
This should work for you.
You can send your sample images on amit.kenjale@gmail.com, I will check datatypes, color formats and sizes of your two images and suggest you better solution that will exactly match to resolve your problem.
[EDIT] Corrected Unit8 to uint8. There is no Unit8 data type.

Iniciar sesión para comentar.

### Respuestas (2)

SALAH ALRABEEI el 5 de Jun. de 2021
No you resize the image it takeout part of the pkls, so the size of the matrices will for sure be smaller. Thus u cannot find the absdiff
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Image Analyst el 5 de Jun. de 2021
Try this and see if it does what you want:
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
%--------------------------------------------------------------------------------------------------------
folder = pwd;
baseFileName = 'cameraman.tif';
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 2, 1);
imshow(grayImage, []);
axis('on', 'image');
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
hFig = gcf;
hFig.WindowState = 'maximized'; % May not work in earlier versions of MATLAB.
drawnow;
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Extract the red channel (so the magenta lines will be white).
grayImage = grayImage(:, :, 1);
end
% Reduce by half.
smallImage = imresize(grayImage, 0.5, 'nearest');
% Display the image.
subplot(2, 2, 2);
imshow(smallImage, []);
axis('on', 'image');
title('Small Image', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
drawnow;
% Grow by a factor of two.
grownImage = imresize(smallImage, 2, 'nearest');
% Display the image.
subplot(2, 2, 3);
imshow(grownImage, []);
axis('on', 'image');
title('Grown Image', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
drawnow;
% Find difference.
diffImage = imabsdiff(grayImage, grownImage);
% Display the image.
subplot(2, 2, 4);
imshow(diffImage, []);
axis('on', 'image');
title('Difference Image', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
drawnow;
% Get the mean difference
meanDiff = mean(diffImage(:))
message = sprintf('The mean difference is %.2f gray levels', meanDiff);
uiwait(helpdlg(message));
##### 2 comentariosMostrar NingunoOcultar Ninguno
GHADAH AL-OBAIDI el 5 de Jun. de 2021
Thank you so much
Image Analyst el 5 de Jun. de 2021
If it does what you want and is acceptable, then please "Accept this answer".
If it does not do what you want, say what needs to be improved to do what you want and be acceptable.

Iniciar sesión para comentar.

### Categorías

Más información sobre Image Arithmetic en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by