Converting idl to matlab and error in code

2 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2017-8-6
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} );

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by