image the same and different

1 次查看(过去 30 天)
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?

采纳的回答

Stephen23
Stephen23 2019-9-10
编辑:Stephen23 2019-9-10
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.

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by