MATLAB Answers

i need to save images with different file names in seperate folders

19 views (last 30 days)
Poreddy ajaykumar reddy
Poreddy ajaykumar reddy on 16 Feb 2021
Answered: Bjorn Gustavsson on 16 Feb 2021
lear all; close all;
inputfilename ='back_5.jpg';
img = imread(inputfilename);
dim = size(img);
width = dim(2);height = dim(1);
gfrgb = imfilter(img, fspecial('gaussian', 3, 3), 'symmetric', 'conv');
cform = makecform('srgb2lab', 'AdaptedWhitePoint', whitepoint('d65'));
lab = applycform(gfrgb,cform);
l = double(lab(:,:,1));
a = double(lab(:,:,2));
b = double(lab(:,:,3));
li = cumsum(cumsum(l,2));
ai = cumsum(cumsum(a,2));
bi = cumsum(cumsum(b,2));
sm = zeros(height, width);
sm2 = zeros(height, width);
for j = 1:height
yo = min(j, height-j);
y1 = max(1,j-yo); y2 = min(j+yo,height);
for k = 1:width
xo = min(k,width-k);
x1 = max(1,k-xo); x2 = min(k+xo,width);
invarea = 1.0/((y2-y1+1)*(x2-x1+1));
lm = iisum(li,x1,y1,x2,y2)*invarea;
am = iisum(ai,x1,y1,x2,y2)*invarea;
bm = iisum(bi,x1,y1,x2,y2)*invarea;
% Compute the saliency map
sm(j,k) = (l(j,k)-lm).^2 + (a(j,k)-am).^2 + (b(j,k)-bm).^2;
img = (sm-min(sm(:)))/(max(sm(:))-min(sm(:)));
now i have six faces like top, front ,bottom, back,left, and right
i need to save images in different folders with image names as top.png, right,png
  1 Comment
Jan on 16 Feb 2021
As far as I understand, the posted code has no relation to the actual problem.
What is the problem with saving the images to different folders?
imwrite(img, 'D:\Your\Folder\top.jpg')

Sign in to comment.

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 16 Feb 2021
You can do this, as Jan hinted at, something like this:
faces = 1:6
face_names = {'top','bottom','front','back','left','right'}; % your image-names
folders2savein = {'run-01','run-02'}
for iRuns = 1:2 % or however many sets you might need
for iFaces = 1:numel(faces)
% Here's where you plug in your processing, for each face and whatever you need
img_type = 'msss'; % In case you have multiple result-files to save
savename = fullfile(folders2savein{iRuns},...
By using fullfile your code will become robust enough to run in different operating systems, and that's one worry less, by generating the file-name this way where you put toghether different parts of the name you're preparing to use this for cases where you save a number of different outputs from the same run and face. Doing it this way will make batch-processing much cleaner.

Community Treasure Hunt

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

Start Hunting!

Translated by