rsummers11 / CADLab

Imaging Biomarkers and Computer-Aided Diagnosis Laboratory

Home Page:https://www.cc.nih.gov/meet-our-doctors/rsummers.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Could I have your kind help to provide the script to convert low contrast image in "Image_png"?

lixiangchun opened this issue · comments

Could I have your kind help to provide the script that did the following steps in the FAQ.pdf in DeepLesion dataset?

  1. Convert the image to int32 format, then subtract 32768 from the pixel intensities to obtain the original Hounsfield unit (HU) values
  2. Do intensity windowing on the HU values
  3. Save the windowed image to 8-bit image files

Please see lesion_detector_3DCE/rcnn/fio/load_ct_img.py.
For example, function load_multislice_img_16bit_png and windowing.
For question 3, please refer to lesion_detector_3DCE/rcnn/core/tester.py, function vis_all_boxes, which is used in fio/image.py, function get_image.

Thanks for your suggestion.

Three more questions.

  1. Is the following code okay?
import load_ct_img as ct
imname = "004432_01_01/072.png"
slice_idx, slice_intv, do_clip, num_slice = 1, 2, False, 1
im, mask = ct.load_multislice_img_16bit_png(imname, slice_idx, slice_intv, do_clip, num_slice)
win = [-175, 250] # obtained from DL_info.csv
im = ct.windowing(im, win)
  1. Currently, I am working on CT imaging data for the first time. I would like to know whether I
    could extract the DICOM_windows values like those in DL_info.csv directly from the original
    dicom data file. Very appreciated in advance if you could give some advise on how to get this
    number.

  2. How to convert dicom data to png file like those in DeepLesion? Any code available here in this repo?

@lixiangchun

  1. Please refer to the function load_prep_img in load_ct_img.py
  2. I believe there is python library to handle dicom files. We used matlab codes to extract information from dicom like this code:
for q = 1:volH
        dicomFile = [dicomDirTmp,d{q}];
	dicomInfo = dicominfo(dicomFile);
	img = dicomread(dicomFile);
		
	try
		img = single(img)*dicomInfo.RescaleSlope + dicomInfo.RescaleIntercept;
	catch
	end
	
	try
		WindowMax = double(dicomInfo.WindowCenter + dicomInfo.WindowWidth/2);
		WindowMax = WindowMax(1);
		WindowMin = double(dicomInfo.WindowCenter - dicomInfo.WindowWidth/2);
		WindowMin = WindowMin(1);
	catch
		if strcmp(dicomInfo.Modality,'CT')
			WindowMax = 500;
			WindowMin = -1000;
		else
			WindowMax = double(max(max(img)));
			WindowMin = double(min(min(img)));
		end
	end
	
	imgSize = size(img);
	if 3 == length(imgSize);
		imgRGB = img;
	else
		if strcmp(save_format,'16bit')
			imgRGB = uint16(img+2^15);
		elseif strcmp(save_format,'8bit')
			imgRGB = uint8(mat2gray(img,[WindowMin WindowMax])*255);
		end
	end
	
	sl = dicomInfo.InstanceNumber;
	imgName = num2str(sl);
	img_pos(sl) = dicomInfo.ImagePositionPatient(3);

	imgName = [save_path,'\',imgName];
	if ~exist([imgName,'.png'],'file')
		imwrite(imgRGB, [imgName,'.png'])
		fprintf(',')
	end
end
intv = -diff(img_pos);
new_intv = abs(mode(intv(~isnan(intv))));
bookMarkTable{p,7}.SliceInterval = new_intv;
info.Window = [WindowMin WindowMax];
info.sliceIntv = sliceIntv;