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.
Related
I am using Canny edge detection on images. Since my original 10 images are in the path folder, C:\Users\X\Desktop\FoodRGB as 01.jpg, 02.jpg, 03.jpg and so on, I want to save all my output images in the folder C:\Users\X\Desktop\FoodCanny as 01.jpg, 02.jpg, 03.jpg.
I figured that I have to use imwrite() function to write the output images in a specific folder but I am not sure about the big idea.
The following code I am using is saving the images as 0%d.jpg in FoodCanny Folder I manually created.
for k = 1:10
img = sprintf('C:\Users\X\Desktop\4\Food Canny\0%d.jpg',k);
imwrite(canny_image, 'C:\Users\X\Desktop\4\Food Canny\0%d.jpg');
end
Supposing you want to get canny edges of all screenshots in the C:\Users\Asus\Pictures\Screenshots and save them to the other folder D:\. You can do this by :
clc;clear all;
fpath = fullfile('C:\Users\Asus\Pictures\Screenshots','*.png');
img_dir = dir(fpath);
for k=1:length(img_dir)
input_image=strcat('C:\Users\Asus\Pictures\Screenshots\',img_dir(k).name);
original = rgb2gray(imread(input_image));
original= edge(original,'canny');
imwrite(original,strcat('D:\',sprintf('edge(%d).jpg',k)));
end
How to add and delete specific image in folder(desktop) through matlab gui?
For example, I have a folder name FLOWER. Then when I open the gui, I can add new image and delete image that have in folder FLOWER. To design the gui i have no problem, but I'm stuck at the code to add and delete image.
Link for screenshot folder:
[https://i.stack.imgur.com/TGDkf.png][1]
To create something, you could call the imwrite function(If I understand you correctly), and delete function could let you delete it.
Here are some demos:
%%Add and Delete image in folder
clc; clear;
%%Case1 : Save a figure
%Create
plot(1:10,1:10);
A=getframe(gcf);
%Write
imwrite(A.cdata,'D:/FLOWER/img1.jpg');
%%Case2 : Create a image
%Create
B=zeros(100:100);
B(1:50,:)=1;
%Write
imwrite(mat2gray(B),'D:/FLOWER/img2.jpg');
%%Case3 : Load and save a image
%Load
C=imread('D:/FLOWER/flower.png');
%Do something with image
%imshow(C);
%C=C/2;
%Write
imwrite(C,'D:/FLOWER/img3.jpg');
%pause
disp('You could check your image now')
pause()
%delete image
delete('D:/FLOWER/img1.jpg')
delete('D:/FLOWER/img2.jpg')
delete('D:/FLOWER/img3.jpg')
To run this demo, "flower.png" have to exist in the folder D:/FLOWER/ and then you will find a copy of it with the name of "img3.jpg"
You could also try copyfile('source','destination') in case3.(if you needn't show/change the image in the GUI)
P.S. you may change the absolute path of your folder since I changed my desktop's path.
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 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 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])