Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

GUI - Saving multiple files to a pre-specified folder

1 visualización (últimos 30 días)
Ellis Berry
Ellis Berry el 7 de Jun. de 2016
Cerrada: Stephen23 el 8 de Jun. de 2016
Hi again everybody,
In this GUI I have made, I want to click 'pushbutton3' to specify a directory where I want to save the processed pictures from my GUI. Here is the code for that pushbutton3 to choose the directory:
% --- Executes on button press in pushbutton3. SAVE
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Choose which folder processed pics will go in.
save_folder_name = uigetdir;
Ok, so now, when I click the 'run' button (pushbutton1) the code runs a loop in which some pictures are processed. As this loop runs I would like it to save each image every iteration to the folder I specified with pushbutton3. I wrote 'imwrite(handles.outDir)' at the end but then I get this error:
Error using imwrite>parse_inputs (line 498)
Wrong number of input arguments.
Error in imwrite (line 418)
[data, map, filename, format, paramPairs] = parse_inputs(varargin{:});
Error in ROI_loop_gui>pushbutton1_Callback (line 134)
imwrite(handles.outDir);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in ROI_loop_gui (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)ROI_loop_gui('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
------------------------------------------------------- Here is my code for pushbutton1:
% --- Executes on button press in pushbutton1. RUN
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
outDir = handles.outDir;
inDir = handles.inDir;
%Specify the folder where the files (Pictures) live. Chosen by pushbutton2
myFolder=handles.outDir;
%Get a list of all files in the folder with the desired file name pattern.
filePattern=fullfile(inDir, '*.JPG');
theFiles=dir(filePattern);
caListBoxItems = cell(length(theFiles), 1);
for k=1:length(theFiles)
RGB = imread(fullfile(inDir, theFiles(k).name));
% if k ==1
% axes(handles.axes1)
% [BW, xi, yi] = roipoly(RGB);
% xMin = min(xi);
% xMax = max(xi);
% yMin = min(yi);
% yMax = max(yi);
% end
newRGB = imcrop(RGB,[handles.xMin handles.yMin handles.xMax-handles.xMin handles.yMax-handles.yMin]);
% Convert RGB image to chosen color space
I = rgb2hsv(newRGB);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.053;
channel1Max = 0.083;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.116;
channel2Max = 0.130;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.608;
channel3Max = 0.643;
% Create mask based on chosen histogram thresholds
BW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
% Invert mask
BW = ~BW;
% Initialize output masked image based on input image.
maskedRGBImage = RGB;
% Set background pixels where BW is false to zero.
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
imwrite(handles.outDir);
end
%Update handles with the outDir
handles.outDir = save_folder_name;
guidata(hObject,handles);
Any help would be greatly appreciated. This seems like an easy fix but I cannot get it to work!
Thanks,
Ellis

Respuestas (1)

Geoff Hayes
Geoff Hayes el 8 de Jun. de 2016
Ellis - imwrite requires (at least) two inputs: the image data and the filename. You are calling imwrite as
imwrite(handles.outDir);
with only one input which is neither an image nor a file name (just a path to some directory). See your other question at http://www.mathworks.com/matlabcentral/answers/288402-gui-saving-image-to-pre-specified-folder which seems to be an updated version of this one.

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by