How can I save outputs in same names of inputs?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
reyadh Albarakat
el 3 de Mayo de 2016
Comentada: reyadh Albarakat
el 4 de Mayo de 2016
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
0 comentarios
Respuesta aceptada
Walter Roberson
el 3 de Mayo de 2016
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 comentarios
Walter Roberson
el 3 de Mayo de 2016
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'];
Más respuestas (0)
Ver también
Categorías
Más información sobre Convert Image Type en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!