Clear Filters
Clear Filters

Haunted Code (Serious)

28 views (last 30 days)
Judy Yang
Judy Yang on 7 May 2020
Commented: Stephen23 on 2 Nov 2023
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
Judy Yang
Judy Yang on 7 May 2020
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
Walter Roberson
Walter Roberson on 2 Nov 2023
Consider using the new Restricted evaluation mode of str2num
Stephen23
Stephen23 on 2 Nov 2023
Consider STR2DOUBLE or SSCANF or any other conversion function that does not rely on EVAL.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!