필터 지우기
필터 지우기

How can I save outputs in same names of inputs?

조회 수: 3 (최근 30일)
reyadh Albarakat
reyadh Albarakat 2016년 5월 3일
댓글: reyadh Albarakat 2016년 5월 4일
Hi everybody,
I create Mask from images. tiff so I want to save output images.tiff in same name of the original images. suppose the names of files are 1981_07_15.n07-VI3g and 1981_07_16.n07-VI3g respectively SO how can I save outputs in same names of inputs.
Thank you in advance
Reyadh
Here is my code
for i=1:length(Ii)
set(0,'DefaultFigureRenderer','zbuffer')
[Plg,Plt]=meshgrid(lg,lt);
LATLIMS=[30.952 32.01];
LONLIMS=[47.09 47.818];
m_proj('Equidistant Cylindrical','lon',LONLIMS,'lat',LATLIMS);
img=Ii{i}.*MASK;
map=m_pcolor(Plg,Plt,img);
a=colormap(jet);
% a=fliplr(a);
set(gcf,'colormap',a);
shading flat;
m_grid('linewi',2,'tickdir','out');
str=num2str(i);
saveas(map,str,'tif');
[Merged from duplicate question]
Hi everybody,
I did mask to multiple images. TIFF then I want ton save the masked images in same name of the original images. Is that possible?
Thank you
Reyadh
Here is my code,
cd G:\marsh\new
F_read=dir('*.tif');
for i=1:2
I{i}= F_read(i).name;
I{i} = imread(I{i});
ID{i}= im2double(I{i});
Ii{i}= ID{i}(697:709,2728:2735);
Ii{i}(Ii{i}>1)=NaN;
Ii{i}(Ii{i}<0)=NaN;
Ii{i}(Ii{i}==0)=NaN;
end
for i=1:13
lt(i)=32.01-0.0833*(i-1);
end
clear i
for i=1:8
lg(i)=47.09+0.0833*(i-1);
end
clear i
cd F:\Landsat_images\All_marshes_Calssification\Alhuwaiza\Mask_Tif
M=m_shaperead('Huwaiza');
%Create a mask
x = linspace(min(lg), max(lg), 8);
y = linspace(min(lt), max(lt), 13);
[x,y] = meshgrid(x,y);
for i=1:length(M.ncst)
Ncst(i,1)=M.ncst{i}(1);
Ncst(i,2)=M.ncst{i}(2);
end
isin = inpolygon(x,y,Ncst(:,1),Ncst(:,2));
isin=flipud(isin);
isin=double(isin);
isin(isin==0)=NaN;
MASK=isin;
clear isin x y
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cd G:\marsh\new\huTif_new
for i=1:length(Ii)
set(0,'DefaultFigureRenderer','zbuffer')
[Plg,Plt]=meshgrid(lg,lt);
LATLIMS=[30.952 32.01];
LONLIMS=[47.09 47.818];
m_proj('Equidistant Cylindrical','lon',LONLIMS,'lat',LATLIMS);
img=Ii{i}.*MASK;
map=m_pcolor(Plg,Plt,img);
a=colormap(Iraqimarsh);
% a=fliplr(a);
set(gcf,'colormap',a);
shading flat;
m_grid('linewi',2,'tickdir','out');
str=num2str(i);
saveas(map,str,'tif');
end

채택된 답변

Walter Roberson
Walter Roberson 2016년 5월 3일
Instead of str = num2str(i) use str = FileNames{i} where FileNames is a cell array of strings of the input file names.
Warning: this will destroy the original files. I would, at the very least, use
str = [FileNames{i} '.tiff'];
so that the output file name is not the same as the input file name.
  댓글 수: 6
Walter Roberson
Walter Roberson 2016년 5월 3일
Sigh, you re-used a variable.
Change your code
I{i}= F_read(i).name;
I{i} = imread(I{i});
to
FileNames{i}= F_read(i).name;
I{i} = imread(FileNames{i});
and then later
str = [FileNames{i} '.tiff'];
reyadh Albarakat
reyadh Albarakat 2016년 5월 4일
Thank you so much Walter. You are the best:)
Reyadh

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by