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

3 次查看(过去 30 天)
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;
end
end
%figure()
%imshow(sm,[]);
img = (sm-min(sm(:)))/(max(sm(:))-min(sm(:)));
imwrite(img,'back_msss.jpg')
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 个评论
Jan
Jan 2021-2-16
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')

请先登录,再进行评论。

回答(1 个)

Bjorn Gustavsson
Bjorn Gustavsson 2021-2-16
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},...
sprintf('%s_%s.jpg',face_names{iFaces},img_type));
imwrite(img,savename)
end
end
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.
HTH

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by