Clear Filters
Clear Filters

Converting idl to matlab and error in code

2 views (last 30 days)
Hi, I'm trying to convert IDL codes to matlab, the idea is i have dark images and flat images and i'm trying to select them both for another section of the code
I'm stuck on the idl function known as FLOAT
IDL codes
flatlist = file_search(workdir,'flat*')
nflat = n_elements(flatlist)
darklist = file_search(workdir,'dark*')
ndark = n_elements(darklist)
dark = fltarr(xsize,ysize)
flat = fltarr(xsize,ysize)
for k = 0,ndark-1 do begin
imtemp = read_tiff(darklist(k))
dark = dark+float(imtemp)/ndark
;Average dark images
endfor
Matlab version
[darklist,workdir] = uigetfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
'*.*','All Files'},'Select the dark image(s)','MultiSelect', 'on');
if(~iscell(darklist))
ndark=1;
else
ndark = numel(darklist);
end
dark = zeros(ysize,xsize);
flat = zeros(ysize,xsize);
for k = 1:ndark
if(~iscell(darklist))
imtemp = imread(darklist);
else
imtemp = imread(darklist{k});
dark = dark+double(imtemp)./ndark;
end
end
I'm not sure if its double, also i'm getting this error
Error in
imtemp = imread(darklist{k});
help pls
Thanks

Accepted Answer

Walter Roberson
Walter Roberson on 6 Aug 2017
IDL's float(x) call corresponds to real(single(x)) in MATLAB. In the case where the data is known to be real-valued already (which is the case for all images except for some advanced TIFF files, and possibly some dicom files), then that would simplify to just single(x)
"also i'm getting this error"
You would not be having that error if you had used the code I gave you in https://www.mathworks.com/matlabcentral/answers/351336-error-trying-to-read-files#answer_276554
The problem is that your files are in some directory other than your current directory. I showed you earlier,
flatlist = fullfile( workdir, {flatinfo.name} );
and
darklist = fullfile( workdir, {darkinfo.name} );

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!