How can I select a folder to save a set of images to?

9 次查看(过去 30 天)
I have been able to plot the centroids to a set of images and have been able to save them using a fixed filepath. I would now like a window to open up so a user could select which folder they would like to save the images to (there are 240 images so would like to categorise them). Is there a way I could alter my code to do this?
bac_pics = tiffread('bacvid.tif'); %imports the tif file
prompt_folder = 'Select a file to save the images to';
prompt_file_name = 'What would you like the image file to be called? ';
[~,locName] = fileparts(input(prompt_file_name),'s')); %saves the name of the image as dictated by the user
for i = 1:numel(bac_pics) %sets up a loop to run for every frame in the video
bac_frame = bac_pics(i).data; %for each loop the fram is named bac_frame
dimensions = size(bac_frame); %finds the sizes of the image
log_filt = fspecial('log'); %creates a filter in the form of a Lorentzian of a Gaussian
bac_frame_filt = imfilter(bac_frame, log_filt); %puts the filter over the image
bw_bac = im2bw(bac_frame_filt , graythresh(bac_frame)); %the image is converted into a bianry image using a limit obatined from a function that uses Otsu's Method
eroder = strel('line', 1, 90); %creates a circular structring element to erode the image later with radius 1
bw_bac_eroded = imopen(bw_bac, eroder); %gets rid of the connecting parts of bacteria
imshow(bac_frame)
baccenter = regionprops(bw_bac_eroded, 'Centroid');%finds the center of each cell
centroids = cat(1, baccenter.Centroid);
centroiddata = regionprops('table', bw_bac_eroded, 'Centroid');
hold on
plot(centroids(:,1),centroids(:,2), 'b*')
hold off
locPath2 = 'C:\Users\nathan\Documents\MATLAB\Tables and Pictures'; %dictates saving location
locFull2 = fullfile(locPath2,[locName, [num2str(i),'.jpg']]);
saveas(gcf,locFull2)
end

采纳的回答

Stephen23
Stephen23 2016-7-29
编辑:Stephen23 2016-7-29
Or perhaps uiputfile. Or whatever suits your task needs: go to the bottom of any MATLAB help page and you will find links to similar functions. Use them!
Oh, and always use fullfile to generate the full file name from a file path and file name:
[FileName,PathName] = uiputfile(...)
filepath = fullfile(PathName,FileName)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Import, Export, and Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by