Dicom Image Reader custom S-Block in Simulink - matlab

I am working on a project related to image processing. I want to create a level-2 S-block in simulink for reading Dicom Images (.dcm). There should be a browse button and edit text section in the Dialog box. Whenever i click on the browse button image can be selected and the path of that image should be displayed on the edit parameter. Any idea what should be the mask callback functions for these parameters. Here is a sample callback for mask parameters. See Sample Image
function DicomReader_callback(action,block)
feval(action,block)
function pushbutton_callback(block)
[fn pn] = uigetfile('*.dcm','select dicom file');
complete = strcat(pn,fn);
get_param(gcb, 'UserData');
set_param(gcb, 'UserData', complete);
function edit_callback(block)
Thanks !

Related

Dicom Images in Matlab gui

I need to make a matlab gui that reads and displays a directory of Dicom files. The gui needs to have a file menu. 2. In the File menu, there is a file Open function which can read the directory of DICOM files. I have no idea how to do this. Can someone help me with this?
Here is some code to get you going. You should absolutely follow this link and try the code provided for yourself. I think this will greatly help you for the remainder of your project and help you understand what is going on as well.
That being said, the following creates a simple figure with an axes to display images. There is also a menu with a button used to open files, in this case DICOM files (.dcm). The hardest part is taken care of my Matlab; you only need to call a function (uigetfile) in the callback of that "open" button and then call the function dicomread to read the content of a dicom file.
I'll leave the rest to you but this should help you get started.If something is unclear please don't hesitate to ask.
Code:
function DicomReadGUI
%// Create figure
hFigure = figure('Position',[200 200 600 600],'MenuBar','none', ...
'Toolbar','none','HandleVisibility','callback');
%// Add an axes just to display an image.
hAxes = axes('Position',[.1 .1 .8 .8],'Parent',hFigure);
%// Add menu in which you will add the "open" button
hFileMenu = uimenu('Parent',hFigure,'HandleVisibility','callback','Label','File');
%// Add a button to browse and open files
hOpenMenuitem = uimenu('Parent',hFileMenu,...
'Label','Open','HandleVisibility','callback', ...
'Callback', #hOpenMenuitemCallback);
%// Callback of the "open" button
function hOpenMenuitemCallback(hObject,eventdata)
%// Browse the computer and select .dcm files.
FileToRead = uigetfile('*.dcm')
[YourImage, ColorMap] = dicomread(FileToRead);
%// Display image in Axes1
imshow(YourImage,'Parent',hAxes)
end
end
And screenshot of the GUI with the button used to unroll a menu from which you can select files to open (circled in red):

Adding a MATLAB GUI to a MATLAB code

I am asked by my professor to add a GUI for my Matlab code. My program receives an image as an input and returns a string.
The GUI should enable me to browse the image and then display it. Then I need to use that image in the Matlab code.
To browse and display the image, I created a pushbutton control and wrote the following in its callback
[baseFileName, folder] = uigetfile('*.jpg');
fullFileName = [folder baseFileName];
rgbImage = imread(fullFileName,'jpg');
imshow(rgbImage);
I added a second pushbutton and the Matlab code (which has a file name main.m) inside its callback. This function needs the image displayed above as an input, and its output (which is a string) needs to be displayed in the GUI.
I am facing a few problems:
I want the image to be displayed in a specific position.
How can I call the function in the push button?
How can I access and use the image in the first push button to the second push button?
Some hints on how you can get started with your problems:
You could create an axes object in your figure, whose position can be defined. then just plot the image on that axes. Do all that in the callback
Calling a function from a callback should not be a problem
Save the image in structure, then you can use for example setappdata and getappdata to pass it between callbacks, i.e. when your figure handle is h.fig and your structure called d:
setappdata(h.fig,'d',d)
in the first callback, and to retrieve it, in the second:
d = getappdata(h.fig,'d');

How to load an image to an axes

I want to load an image from a particular folder to an axes when I push a button in my MATLAB GUI. I have tried this code, it lets me select the picture I want but it does not load it to the axes. Can someone assist me on this please?
[File_Name, Path_Name] = uigetfile()
fullImageFileName = fullfile(Path_Name, File_Name);
Selected_Image = imread(fullImageFileName );
imshow([Selected_Image ,handles.axes1])

content based image retrieval graphical user interface

I am making a project named content based image retrieval using color. I have implemented my algorithm. Now I have to make a GUI.
How can I call my algorithm function in the callback function of a push button?
By pushing the button my query and database images should display on GUI.
function pushbutton1_Callback(hObject, eventdata, handles)
[FileName, folderName] = uigetfile('.','specify an image file');
fullimageFilename=fullfile(folderName,FileName); im=imread(fullimageFilename); query(im);
image(im,'parent',handles.axes2);

Save image from axes in MATLAB

I generate a picture in an axes that is called newIM when I click on the apply button.
Now, I want to save this new picture in a jpg, gif, bmp or whatever file when I push the save button.
This is what I had:
pathname = 'D:\pictures\';
filename = 'Test.bmp';
both = strcat(pathname, filename);
imshow(both);
imsave('test','*.jpg')
But this is only for a Test.bmp and not for the picture in newIM.
How can I make this variable?
Use getfame:
F = getframe(gcf);
image(F.cdata);
imwrite(F.cdata, 'file.jpg');
If it's in some gui or other plots I usually use copyobj to copy the axes containing the picture and add them to a new (usually hidden) figure window.