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])
Related
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 !
i can create an axes and use the axes() to define the axes i want to display my image in it , but that's not working cause i have this message :
http://img.prntscr.com/img?url=http://i.imgur.com/s6wNRZF.jpg
there is any other way to display image in the position i want ?
for example :
showimg('link',position)
my code that i recieve the error from :
img = imread(2.png);
axes(handles.axes7);
imshow(img);
You should directly pass the file name to imshow and, then, add the reference to the axis handle when calling imshow:
imshow('2.png','parent',handles.axes7)
Hope this helps.
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):
I'm making a GUI in MatLab that asks the user to upload a video file.
Next I want to play it in axes with a fixed window size . However, if the uploaded file is large, Matlab will expand the axes and take over most of my GUI. Is there a way to shrink the image to make it fit the axes?
Does anyone know how to solve this?
Usually Matlab axes are not supposed to change their position if the image is too big.
I can think of two possible problems:
The axes were large from the beginning, but showed small image with margins if the image is small enough
The command of showing the image that you are using is custom and it changes the axes size.
This question is old, but I stumbled across this (looking for something else) so perhaps it will help someone to see what I did.
I wanted to resize pretty large images (1024x 100k-200k pixels) so that my GUI can quickly demonstrate various color operations on a view of these large data sets. I just manually sub-sampled my data as follows (functions below).
Note that this example is an image. To spatially sub-sample a video, I have looped through the video and done something similar in the past on each frame.
[plotWidthPixels, plotHeightPixels] = getPlotAreaPixels(handles.figure1, handles.axes1);
[nSamplesPerLine nLines] = size(iqData);
colInds = decimateToNumber(nLines,plotWidthPixels);
rowInds = decimateToNumber(nSamplesPerLine,plotHeightPixels);
iqDataToPlot = iqData(rowInds,colInds);
First, I got the axis size in pixels:
function [plotWidthPixels, plotHeightPixels] = getPlotAreaPixels(figHandle, axisHandle)
set(figHandle,'Units','pixels')
figSizePix = get(figHandle,'Position');
set(axisHandle,'Units','normalized')
axSizeNorm = get(axisHandle,'Position');
axisSizePix = figSizePix.*axSizeNorm;
plotWidthPixels = ceil(axisSizePix(3)-axisSizePix(1));
plotHeightPixels = ceil(axisSizePix(4)-axisSizePix(2));
Then I used that to decimate the width and height of my image by getting sub-sets of indices that are (crudely approximately) evenly spaced:
function inds = decimateToNumber(lengthOfInitialVector, desiredVectorLength, initialIndex)
if nargin < 3
initialIndex = 1;
end
if (lengthOfInitialVector-initialIndex+1) > desiredVectorLength*2
inds = round(linspace(initialIndex,lengthOfInitialVector,desiredVectorLength));
else
inds = initialIndex:lengthOfInitialVector;
end
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.