I know this might sound like a joke but I promise I am being completely serious. I want to preface this question by saying that I don't need help fixing this code, I've rewritten it and it works fine now. I am simply looking to see if anyone knows why this is happening or if it has happened to anyone else
I've been trying to create a GUI where I can click a button, use it to select an image, and then display that image on an axes. All was going well but when I went to test the code (as follows), the image loaded with a small blue square in the corner. Looking closer at that box, I found that there is an image of what appears to be a young boy smiling (3 images attached below show him appearing on 2 different images and then one zoomed in on him). He appears on every image I've tried, in various sizes. I am 99% certain this is not an image from my local storage; my device is brand new and I cannot fathom as to why I would have such an image saved somewhere.
% --- Executes on button press in LoadButton.
function LoadButton_Callback(hObject, eventdata, handles)
% hObject handle to LoadButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, path]=uigetfile('*.jpg','Select an Image')
fullfilename=fullfile(path,filename)
Image= imread(fullfilename);
image(Image,'Parent',handles.Image);
set(handles.Image,'visible');
imshow(image);
If anyone has any idea what's going on please let me know.

3 Comments

the functin "image" wihout arguments shows that boy by default (yes, it's ridiculous)
The below code shows something similar to yours
you don't need the imshow(image) call
or at least call imshow(Image)
(better not distinguish names on capitalization alone)
clf
M1=imread('peppers.png'); % comes with matlab
image(M1);
hold on
imshow(image) % first displays the default image and then throws an error (wrong input for imshow)
Oh thanks for the info about the image. I already rewrote the code entirely though so don't worry about troubleshooting. Was just confused on where the image was from.
Stephen23
Stephen23 on 7 May 2020
Edited: Stephen23 on 7 May 2020
That is the default image. See:
It gets shown in your axes because of this superfluous line of code:
imshow(image);
where you call image without an input argument, hence it shows the default image. Solution: get rid of that line.

Sign in to comment.

 Accepted Answer

Tommy
Tommy on 7 May 2020
Edited: Tommy on 7 May 2020
That is the default image upside down. You can view it by calling just
>> image
When you call
imshow(image);
MATLAB first evaluates image and shows the default image in the current axes. I believe it then tries to call imshow() on the output of image, which is an Image object, and so it should throw an error (it does for me). You will see the blue kid in the corner (and the error) with the following three lines:
Image = imread('pears.png');
image(Image);
imshow(image);
The image is actually first being plotted with the call to image() - you don't need the third line.
I'm assuming handles.Image is supposed to be the axes where you are plotting your image. How about this instead?
Image = imread(fullfilename);
image(handles.Image, Image); % or, imshow(Image, 'Parent', ax); if you'd like
(edit) And it's not just a boy :)

5 Comments

That easter egg post was very interesting, thank you! I realized a lot of the other stuff you've mentioned and already fixed the code so you don't need to worry about helping me troubleshoot but thank you for that too.
Ed
Ed on 2 Nov 2023
I have also discovered that
str2num('image not found')
also displays this default image. This was quite a surprise, especially as 'image not found' was an unexpected string found in a large dataset which should only have been numbers.
Correct. This is because, as the documentation page for the str2num function states, "str2num is implemented using eval which might lead to undesired side effects."
Consider using the new Restricted evaluation mode of str2num
Consider STR2DOUBLE or SSCANF or any other conversion function that does not rely on EVAL.

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Tags

Asked:

on 7 May 2020

Commented:

on 2 Nov 2023

Community Treasure Hunt

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

Start Hunting!