image the same and different

1 visualizzazione (ultimi 30 giorni)
lol lolol
lol lolol il 10 Set 2019
Commentato: lol lolol il 10 Set 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?

Risposta accettata

Stephen23
Stephen23 il 10 Set 2019
Modificato: Stephen23 il 10 Set 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.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by