Hello all,
I'm trying to rescale image histograms for several hundred scans using
Jason Steffener's code (below). However, after doing several of these, I
realize that this process is tedious, and since histograms vary between
one scan and another, it would be ideal if there is a way to calculate
min and max intensity values for each image and rescale the histogram
accordingly, and do this recursively for a directory of files. Does
anyone have such code already written or knows the best way to proceed
about this? I've attached Jason's code below, since I figured this might
be a good start.
I'm not a Matlab expert by any stretch of imagination, so any help would
be appreciated!
Thanks
Mike
----------------------------
P=spm_get(1,'*.img','Choose the image to work with')
fg = spm_figure('Findwin','Graphics');
spm_figure('Clear',fg);
handle(fg)=spm_orthviews('Image',P,[0.005 0.3 0.49 1]);
figure(fg);
title('Original Image');
Vi=spm_vol(P);
d=spm_read_vols(Vi);
[h,b]=hist(reshape(d,prod(size(d)),1),250);
fg = spm_figure('Getwin','Graphics');
figure(fg);
subplot(4,1,4)
plot(b,h);
T=spm_input('Enter Truncation Value');
minthreshvalue=10;
Vo=Vi;
[path name ext]=fileparts(Vo.fname);
Vo.fname=fullfile(path,['T' name ext])
d(find(d<0))=NaN;
d(find(d>T))=NaN;
Vo=spm_write_vol(Vo,d);
disp('Done');
TI=cat(2,'Image trunacted at ', num2str(T));
handle(fg)=spm_orthviews('Image',Vo.fname,[0.505 0.3 0.49 1])
figure(fg);
title(TI);
--------------------------
|