Saving All Image files in a UITable in App Designer
Show older comments
Hi, I'm trying to write a code where I have image files in my UITable (all listed in column 1) and I would like to have a save all image on my menu bar. What I'm having trouble with is finding a way to call all the images listed in my UITable and running those listed images again and save each image under an updated filename in a new folder.
Here is what I have so far:
filter = {'*.jpg';'*.png';'*.tif';'*.pdf';'*.eps'};
[filename,filepath] = uiputfile(filter);
app.UITable.Data = [app.UITable.Data;app.EDUcolorDATA];%%MY TABLE WITH ALL THE IMAGE FILES
filepath = app.UITable.Data{:,1};
h=1;
while h<=length(filepath)
close all
img = imread(filepath{h,1});
EDUInitialThresholding
mask = 100./app.mask;
EDUThresholdRefining
[pathstr,name,parts] = fileparts(filepath{h,1});
newname = sprintf('%s_processed', name);
newname1 = [name, parts];
if ischar(newname1)
exportgraphics(figure(1),[filepath newname1]);
end
h=h+1;
end
When I run this code, I encounter an error where img = imread(filepath{h,1}); Error: Brace indexing is not supported for variables of this type.
How would I go about looping each image file I have, then running my algorithm and saving each image file with an updated name?
Answers (1)
Mario Malic
on 4 Nov 2020
Hello,
Here's some code, but it's not tested. I don't know which one of your functions display the processed images, you can use an UIAxes or use function gca to get handle of currently active axes, therefore you don't need to open and close the figure all the time.
filter = {'*.jpg';'*.png';'*.tif';'*.pdf';'*.eps'};
[filename,filepath] = uiputfile(filter);
app.UITable.Data = [app.UITable.Data;app.EDUcolorDATA];%%MY TABLE WITH ALL THE IMAGE FILES
filepath = app.UITable.Data{:,1};
% ax = app.PreviewImagesUIAxes; % If you want to create this component
% ax = gca; % If you want to plot on existing axes
for ii = 1 : 1 : length(filepath)
img = imread(filepath{ii,1});
EDUInitialThresholding
mask = 100./app.mask;
EDUThresholdRefining
[pathstr,name,parts] = fileparts(filepath{ii,1});
newname = sprintf('%s_processed%s', name, parts);
exportgraphics(ax,fullfile(filepath, newname));
end
1 Comment
Raymond Briones
on 4 Nov 2020
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!