Akzeptierte Antwort

Chandra Kurniawan
Chandra Kurniawan am 9 Jan. 2012

2 Stimmen

Hi, Usama
Here I give you sample code with GUIDE.
First, you need to create your GUI.
Type 'guide' in command window, and select 'blank GUI'
Then design your GUI. Your GUI must contains Axes, Pushbutton, and Edit as shown in the picture bellow
And type this code at 'pushbutton1_Callback'
function pushbutton1_Callback(hObject, eventdata, handles)
handles.output = hObject;
[fn pn] = uigetfile('*.dcm','select dicom file');
complete = strcat(pn,fn);
set(handles.edit1,'string',complete);
I = dicomread(complete);
imshow(I,[]);
guidata(hObject, handles);
I hope this clear.

13 Kommentare

Usama Javed
Usama Javed am 9 Jan. 2012
I dont know what the hell is wrong with set(handles.edit1,'string',complete);
still its giving an error... :(
Following are the errors arising... I shall be thankful if u help me to solve these errors...
??? Reference to non-existent field 'edit1'.
Error in ==> BrowseButton>btnbrowse_Callback at 105
set(handles.edit1,'string',complete);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> BrowseButton at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)BrowseButton('btnbrowse_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
Usama Javed
Usama Javed am 9 Jan. 2012
oo i got it...
i changed the tag of edit text... it was my own mistake... thank u soo much...
now its working fine...
Usama Javed
Usama Javed am 9 Jan. 2012
i have uploaded another question regarding to showing dicom image... can u plz help me in that...???
Chandra Kurniawan
Chandra Kurniawan am 9 Jan. 2012
Yes,
just show me the page.
Usama Javed
Usama Javed am 9 Jan. 2012
O thanks God and thanks to u Chandra... got my answer after reviewing the code... thank u soo much...
Usama Javed
Usama Javed am 9 Jan. 2012
why cant i apply rgb2gray to dicom image... its giving an error...
>> I = dicomread('\C:\Users\Asad\Documents\MATLAB\1.dcm');
>> I=rgb2gray(I);
??? Error using ==> rgb2gray>parse_inputs at 82
MAP must be a m x 3 array.
Error in ==> rgb2gray at 35
X = parse_inputs(varargin{:});
Chandra Kurniawan
Chandra Kurniawan am 9 Jan. 2012
Of course.
Because size of your DICOM image is m x n (2 dimentional).
The rgb2gray function takes m x n x o (3 dimentional) size.
Usama Javed
Usama Javed am 9 Jan. 2012
so is there any other way to apply rgb2gray on dicom image...
Chandra Kurniawan
Chandra Kurniawan am 9 Jan. 2012
Please tell me the size of your dicom image by typing
size(I) in command window.
Usama Javed
Usama Javed am 9 Jan. 2012
512 * 512
Usama Javed
Usama Javed am 23 Jan. 2012
hi,
can you tell me how can i get that address from edit text box.
Michal Urban
Michal Urban am 20 Nov. 2016
Hi, i have one problem, when i use this code , still not working , can u someone help me? I have 4 files dicom data and i need code for showing this data.
Image Analyst
Image Analyst am 20 Nov. 2016
Michal, post your code and image in a new thread.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (7)

Junaid
Junaid am 5 Jan. 2012

1 Stimme

Dear Usman,
If I understand you correct. You mean how to browse image from GUI right?
If yes then it is as follow:
a=imgetfile;
where a is your image.

1 Kommentar

Usama Javed
Usama Javed am 5 Jan. 2012
actually i m trying to read an image from browse control.. i-e
there will be an edit text control and a push button(browse Button).. the path will set in that edit text box so that i can read an image at that path

Melden Sie sich an, um zu kommentieren.

Chandra Kurniawan
Chandra Kurniawan am 5 Jan. 2012

1 Stimme

[fn pn] = uigetfile('*.dcm','select dicom file');
complete = strcat(pn,fn);
set(handles.edit1,'string',complete);
I = dicomread(complete);

2 Kommentare

Usama Javed
Usama Javed am 8 Jan. 2012
??? Undefined function or variable 'handles'.
Error in ==> Untitled at 3
set(handles.edit1,'string',complete);
Chandra Kurniawan
Chandra Kurniawan am 9 Jan. 2012
Hi,
Here, I Just give you little hint.
Of course you cannot apply my code directly to your script.
You need to do your own modification.

Melden Sie sich an, um zu kommentieren.

Image Analyst
Image Analyst am 5 Jan. 2012

0 Stimmen

Try MAGIC:
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. The user can optionally apply a mask (region of interest) to the image so that only the area within the mask will be analyzed. The results are optionally sent to Excel. In this demo, I do some very basic particle sizing but in use, the user would replace that simple demo code in the function AnalyzeSingleImage() with their own code. Works with Windows or Unix since paths are all forward slashes. Requires the Image Processing Toolbox to do the simple particle sizing demo, but if you delete that demo code before using it, then the IP toolbox would not be required and it would still demonstrate the basic GUI-based file processing functionality.
Seema
Seema am 24 Mär. 2012

0 Stimmen

Hi Chandra, I executed the above code & it's working for me. But could u plz tell me which line in ur code enables the image selected to be displayed in the axes. Actually I'm not able to understand the meaning of the line "handles.output = hObject; [fn pn] = uigetfile('*.dcm','select dicom file'); "
Regards, Seema

1 Kommentar

Image Analyst
Image Analyst am 25 Mär. 2012
The "getfile()" line gets the filename (a string). imread() reads in the image from disk into a variable in your program. The "imshow()" line is the line that does the actual displaying of the image.

Melden Sie sich an, um zu kommentieren.

msp
msp am 12 Apr. 2013

0 Stimmen

how to get path of uigetfile?

1 Kommentar

Image Analyst
Image Analyst am 12 Apr. 2013
You posted this as an answer to Usama's question, but it's obviously not an answer to his question. So, if it's supposed to be a comment or followup question on one of the actual answers, whose answer are you commenting on? If you intended this to be a brand new discussion question of your own, then please post it as a new question, not as an answer.

Melden Sie sich an, um zu kommentieren.

Muthukumar Thangam
Muthukumar Thangam am 7 Sep. 2013

0 Stimmen

% Try this for browse and load jpg images
% code
function pushbutton1_Callback(hObject, eventdata, handles)
handles.output = hObject;
[fn pn] = uigetfile('*.jpg','select jpg file');
complete = strcat(pn,fn);
set(handles.edit1,'string',complete);
I = imread(complete);
imshow(I,[]);
guidata(hObject, handles);

4 Kommentare

kiran
kiran am 3 Apr. 2014
pls say me how to display the selected image? and also how to save the image to a variable?
Image Analyst
Image Analyst am 3 Apr. 2014
imshow() displays it. imread() "saves" the image from disk to a variable in your program.
i think you have misunderstood my question.
if true
% code
function pushbutton1_Callback(hObject, eventdata, handles)
handles.output = hObject;
[fn pn] = uigetfile('*.jpg','select jpg file');
complete = strcat(pn,fn);
set(handles.edit1,'string',complete);
I = imread(complete);
imshow(I,[]);
guidata(hObject, handles);
end
this is the code i used to browse the image when i click the pushbutton on the gui. now when i click the browse button i need to select an image from the drive, i need to display the image and i need to save the image to a variable so that i will be able to use it when i click the convert button.
Image Analyst
Image Analyst am 4 Apr. 2014
I did answer the original questions about how to display (use imshow) and how to put the image into a variable (use imread). For your new question about how to access the image when you click a different push button, see the FAQ http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F

Melden Sie sich an, um zu kommentieren.

Thirunavukkarasu
Thirunavukkarasu am 6 Feb. 2015

0 Stimmen

What must be the size of the axes to load the .jpg image? how can we relate the size of the image with the size of the axes ?

1 Kommentar

Image Analyst
Image Analyst am 6 Feb. 2015
They're independent. Your image will scale to fit whatever size your axes is.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Convert Image Type finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by