필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

GUI - Saving multiple files to a pre-specified folder (EDIT)!!

조회 수: 1 (최근 30일)
Ellis Berry
Ellis Berry 2016년 6월 7일
마감: Stephen23 2016년 6월 7일
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;
%Update handles with the outDir
handles.outDir = save_folder_name;
guidata(hObject,handles);
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
Any help would be greatly appreciated. This seems like an easy fix but I cannot get it to work!
Thanks,
Ellis

답변 (0개)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by