image the same and different

1 visualización (últimos 30 días)
lol lolol
lol lolol el 10 de Sept. de 2019
Comentada: lol lolol el 10 de Sept. de 2019
I have a function:
function [transformed, image] = transformImage(host,transformMatrix)
host=im2double(host);
imageR=transformMatrix * host(:,:,1)*transformMatrix;
imageG=transformMatrix * host(:,:,2)*transformMatrix;
imageB=transformMatrix * host(:,:,3)*transformMatrix;
transformed(:,:,1)=imageR;
transformed(:,:,2)=imageG;
transformed(:,:,3)=imageB;
image = transformed;
transformed = im2uint8(image);
if transformed==im2uint8(image)
disp("1. true")
else
disp("1. false")
end
end
and main:
[image, transformedImage] = transformImage(host, transformMatrix);
if transformedImage==im2uint8(image)
disp("2.true")
else
disp("2.false")
end
and result is:
1. true
2.false
why inside function is tthe same, and outside is different?

Respuesta aceptada

Stephen23
Stephen23 el 10 de Sept. de 2019
Editada: Stephen23 el 10 de Sept. de 2019
You swapped the order of the output arguments when you called the function.
Here is the function definition:
function [transformed, image] = transformImage(...)
But here is how you called the function:
[image, transformedImage] = transformImage(...)
MATLAB has positional input/output arguments. Their names are totally irrelevant.
You swapped the order, so you got the uint8 image in image (the 1st output) and the double image in transformedImage (the 2nd output). Then you converted the uint8 image into a uint8 image (doing nothing whatsoever) and compared that to the double image.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by