Sorting dicom images in Matlab -


i working lung data sets in matlab, need sort slices correctly , show them.

i knew can done using "instance number" parameter in dicom header, did not manage run correct code.

how can that?

here piece of code:

dicom_directory = uigetdir(); sdir = strcat(dicom_directory,'\*.dcm'); files = dir(sdir); = strcat(dicom_directory, '\',files(i).name); x = repmat(double(0), [512 512 1 ]); x(:,:,1) = double(dicomread(i)); axes(handles.axes1); imshow(x,[]); 

first of all, dicom header, need use dicominfo return struct containing each of fields. if want use instancenumber field sort by, can in such way.

%// of files directory = uigetdir(); files = dir(fullfile(directory, '*.dcm')); filenames = cellfun(@(x)fullfile(directory, x), {files.name}, 'uni', 0);  %// ensure dicom files , remove ones aren't notdicom = ~cellfun(@isdicom, filenames); files(notdicom) = [];  %// load dicom headers array of structs infos = cellfun(@dicominfo, filenames);  %// sort these instance number [~, inds] = sort([infos.instancenumber]); infos = infos(inds);  %// can loop through , display them dcm = dicomread(infos(1)); him = imshow(dcm, []);  k = 1:numel(infos)     set(him, 'cdata', dicomread(infos(k)));     pause(0.1) end 

that being said, have careful sorting dicoms using instancenumber. not robust way of doing because "instancenumber" can refer same image acquired on time or different slices throughout 3d volume. if want 1 or other, choose more specific.

if want sort physical slices, recommend sorting slicelocation field (if available). if sorting time, use triggertime (if available).

also need consider there potentially multiple series in folder maybe consider using seriesnumber differentiate these.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -