How to have the input files labels in the output files

1 次查看(过去 30 天)
I'm cropping some files and I want to keep the labels of the input files in the output files. Any idea to achieve that please.
imgFolderStokes = fullfile('Data/Stokes_Parameters/');
imgStokes = imageDatastore(imgFolderStokes);
numOfImgStokes = length(imgStokes.Files);
for ii = 1:numOfImgStokes
Stokes{ii} = fitsread(imgStokes.Files{ii})
targetSize = [244 234];
r = centerCropWindow2d(size(Stokes{ii}),targetSize);
J = imcrop(Stokes{ii},r);
fitswrite(J,'myfile.fits')
end

回答(1 个)

Mathieu NOE
Mathieu NOE 2021-7-19
hello
my 2 cents suggestion :
imgFolderStokes = fullfile('Data/Stokes_Parameters/');
imgStokes = imageDatastore(imgFolderStokes);
numOfImgStokes = length(imgStokes.Files);
for ii = 1:numOfImgStokes
input_filename = imgStokes.Files{ii};
Stokes{ii} = fitsread(input_filename)
targetSize = [244 234];
r = centerCropWindow2d(size(Stokes{ii}),targetSize);
J = imcrop(Stokes{ii},r);
% % if input_filename contains a dot plus a 3 letters extension,
% % uncomment this line bellow :
% input_filename = input_filename(1:length(input_filename)-4); % optionnal
fitswrite(J,[input_filename '_out.fits'])
end
  7 个评论
Walter Roberson
Walter Roberson 2021-7-22
outputdir = fullfile('Output_Fits');
if ~isdir(outputdir); mkdir(outputdir); end
stuff
fitswrite(J, char( fullfile(outputdir, input_file+"_out.fits")))
assia assia
assia assia 2021-7-22
I still have the same error even though with char. Here's the code that I 'm trying to make it work:
imgFolder = fullfile('/ircnn_color/');
img = imageDatastore(imgFolder);
numOfImg = length(img.Files);
outputdir = fullfile('/results_convert_fits/');
for ii = 1:numOfImg
input_filename = img.Files{ii};
image = imread(input_filename,'png');
fitswrite(image, char(fullfile(outputdir, input_filename+"_out.fits")))
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by