Effacer les filtres
Effacer les filtres

error trying to read files

1 vue (au cours des 30 derniers jours)
hasan alhussaini
hasan alhussaini le 2 Août 2017
Hi
I'm struggling with the current code i'm translated from idl, basically I've got a list of darkfield images named dark1,dark2,dark3,dark4,dark5. and a list of flatfield images named flat1,flat2,flat3,flat4,flat5 i'm trying to create a loop on the darkfield images and flatfield images and calculate their average using the code below. i get an error when the code starts a loop for k = 1:ndark
filesAndFolders = dir(workdir);
filesInDir = filesAndFolders(~([filesAndFolders.isdir])); % Returns only the files in the directory
j=1;
for i=1:length(filesInDir)
if(strfind(filesInDir(i).name,'flat'))
flatlist{j} = filesInDir(i).name;
j=j+1;
end
end
nflat = numel(flatlist);
%darklist = file_search(workdir,'dark*')
j=1;
for i=1:length(filesInDir)
if(strfind(filesInDir(i).name,'dark'))
darklist{j} = filesInDir(i).name;
j=j+1;
end
end
ndark = numel(darklist);
dark = zeros(ysize,xsize);
flat = zeros(ysize,xsize);
for k = 1:ndark
imtemp = imread(darklist{k});
dark = dark+double(imtemp)./ndark;
% ;Average dark images
end
for k = 1:nflat
imtemp = imread(flatlist{k});
flat = flat+double(imtemp)./nflat;
%;Average flat image
end
flatsub = flat-dark;
flatsub(find(flatsub <= 0)) = 1;

Réponse acceptée

Walter Roberson
Walter Roberson le 2 Août 2017
flatinfo = dir( fullfile(workdir, 'flat*') );
flatlist = fullfile( workdir, {flatinfo.name} );
nflat = numel(flatlist);
darkinfo = dir( fullfile(workdir, 'dark*') );
darklist = fullfile( workdir, {darkinfo.name} );
ndark = numel(darklist);
flat = zeros(ysize,xsize);
for K = 1 : nflat
imtemp = imresize( imread(flatlist{k}), [ysize, xsize] );
flat = flat + double(imtemp);
end
flat = flat ./ nflat;
dark = zeros(ysize,xsize);
for K = 1 : ndark
imtemp = imresize( imread(darklist{k}), [ysize, xsize] );
dark = dark + double(imtemp);
end
dark = dark ./ ndark;
flatsub = flat - dark;
flatsub(flatsub <= 0) = 1;
But are you sure that you want to set the zero / negative areas to 1 and not to 0? To me it would make more sense to use
flatsub = max(0, flat - dark);
which would use 0 for places that would have been negative.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by