image the same and different
1 view (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Stephen23
on 10 Sep 2019
Edited: Stephen23
on 10 Sep 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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!