Errors with imshow function
11 次查看(过去 30 天)
显示 更早的评论
回答(2 个)
Walter Roberson
2023-2-17
There is no variable named image in your P2image.mat file, so your second line is being interpreted as
imshow(image())
When you call image() with no parameters, it creates an image object with a default image (that has a bunch of easter-eggs hidden in it.) The handle of the image() object is returned and is passed to imshow(). But imshow() cannot accept handles to image() objects, and so gives an error message.
We recommend that you do not use load() without assigning the result to a variable. For example,
datastruct = load('P2image.mat');
P2image = datastruct.P2image; %if the variable is named P2image in the file
imshow(P2image)
There is one other possibility:
If you had this code inside a function, then there might have been a variable named image inside the mat file after all. However, inside functions, MATLAB is explicitly permitted to refuse to pay attention the possibility that you might be "poofing" a variable into existence where the variable just happens to have the same name as a function. MATLAB is permitted to continue to treat references to the name as functions. This applies only when the variable that has the same name as a function is created by using load() without outputs, or by using evalin() or assignin() . [Note: The syms command is actually a function that uses assignin() so variables created using syms are potentially affected by this rule.]
0 个评论
Voss
2023-2-17
The image function creates an image object.
The imshow function creates an image object and does other stuff to the axes, given an array of image data. When you pass imshow an image object rather than an array of image data, you get that error.
imshow(image)
Notice the error essentially says, "Expected input #1 to be numeric (or logical) but it was an image object instead."
To avoid this error, you should pass imshow an array of image data; I imagine that would be one of the variables stored in P2image.mat, but I couldn't say which one, since I don't have that file.
0 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!