how i can upload a picture using gui when i push a pushbutton

32 views (last 30 days)
i want in gui that is there is a pushbutton name ,upload, and when i push it then it will automatically open a folder from where i want to add any image
  1 Comment
priyatham b
priyatham b on 24 Mar 2017
Edited: priyatham b on 24 Mar 2017
[filename, pathname] = uigetfile('*.*','D:\Users\Public\Pictures\Sample Pictures');
img=imread([pathname, filename]);
imshow(img,'Parent',handles.axes1);

Sign in to comment.

Answers (2)

Andrew Reibold
Andrew Reibold on 11 May 2013
Edited: Andrew Reibold on 11 May 2013
Hi Sajid,
Do you mean you want to push the button, select an image from a folder, and then load the image to the screen?
If thats what you mean, this is what you do. ...
1) Add an axis into your GUI where you want the picture to show up.
-----This is done very easily in GUIDE, there is a button to create an axis on the left panel
2) Edit the push button callback to include the following
[File_Name, Path_Name] = uigetfile('PATHNAME')
axes('handles.myaxistag')
imshow([Path_Name,File_Name])
Above, PATHNAME is the location of the folder that your picture is located in.
...
AN EXAMPLE : )
...
If I have a situation where the location of my picture is 'D:\Users\Public\Pictures\Sample Pictures' and the TAG property of my axis is myaxistag, my code would look like this inside of the push button callback:
[File_Name, Path_Name] = uigetfile('D:\Users\Public\Pictures\Sample Pictures')
axes('handles.myaxistag')
imshow([Path_Name,File_Name])
If you do not know the location of your file, or if it might change, just leave it blank and it will be ok.
...
EXPLANATION IF YOU WANT TO KNOW WHAT IS HAPPENING
...
When you press the button the code will activate. The first line will open a window for you to select the picture you want to load. The PATHNAME just helps you find it faster.
The second line selects the axis. It tells the computer "This is what I want you to keep in mind right now"
The last line takes the file location from the first line, and tries to load it as an image where ever the "Computer is thinking of right now", in this case, the axes we selected.
Hopefully now your image is showing!
...
Disclaimer: I have not test run that code. Just off the top of my head.
Message or comment if it doesn't work, I will try to get back with you!
-Andrew Reibold
  3 Comments
Image Analyst
Image Analyst on 18 Mar 2015
Both of you: show your code. How can we give advice if you don't show your code. If you were an expert, would you be able to answer a question like that with what was provided? Please read this: http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
D LQ
D LQ on 17 Mar 2017
Hi :), if someone read that, the code shown by Andrew is correct, however, I changed the line
axes('handles.myaxistag')
with (i.e. without quotes):
axes(handles.myaxistag)
where "handles" is defined by the sign of function
function buttonToLoadImage_Callback(hObject, eventdata, handles)
Regards ñ_ñ

Sign in to comment.


Image Analyst
Image Analyst on 11 May 2013
Description
This GUI will help the novice user get up to speed very quickly on using GUI-based applications. Everything is laid out in a very simple Step 1, Step 2, Step 3, etc. layout. It is a very good starting point for a typical image analysis application. This application uses GUIDE to do the user interface design, and has most of the basic controls such as buttons, listboxes, checkboxes, radio buttons, scrollbars, etc. It allows the user to select a folder of images, select one or more images and display them, to select a series of options, and to individually or batch process one or more images. .........

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!