Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pixel Data Not Found #91

Open
Dale-Black opened this issue Jul 26, 2024 · 4 comments
Open

Pixel Data Not Found #91

Dale-Black opened this issue Jul 26, 2024 · 4 comments

Comments

@Dale-Black
Copy link
Contributor

I will try to get around to diagnosing this issue, but for some reason the pixel data from this image (from a new photon counting CT) is not found using DICOM.jl but works fine with pydicom

Here is my Julia attempt:

using DICOM: @tag_str, dcm_parse

function rescale_dcm(dcm_path)
	dcm = dcm_parse(dcm_path)
	header = dcm.meta
	pixel_array = header[tag"Pixel Data"]

	...
	
end

low_energy_image = rescale_dcm(path_70_keV)

Which errors:

KeyError: key (0x7fe0, 0x0010) not found

Stack trace
Here is what happened, the most recent locations are first:

getindex @ dict.jl:498
(::Main.var"workspace#30".var"#rescale_dcm#1")(dcm_path::String) @ [This cell: line 7](http://0.0.0.0:1235/edit?id=91b38720-4b92-11ef-2fef-6d356e0327f4#98202d78-20f0-4259-a919-1e24f3450fd4)
	header = dcm.meta
	pixel_array = header[tag"Pixel Data"]
[Show more...](http://0.0.0.0:1235/edit?id=91b38720-4b92-11ef-2fef-6d356e0327f4#)

Whereas with pydicom (via PythonCall)

function rescale_pydicom(dcm_filepath)
	# Read the DICOM file
	data = pydicom.dcmread(dcm_filepath)

	# Get the pixel array
	pixel_array = data.pixel_array

	# Get RescaleSlope and RescaleIntercept, with default values as second args
	rescale_slope = pygetattr(data, "RescaleSlope", 1.0)
	rescale_intercept = pygetattr(data, "RescaleIntercept", 0.0)

	image = (pixel_array * rescale_slope) + rescale_intercept
	
	return pyconvert(Array{Float64}, image)
end

this works completely fine.

MonoE 70keV 200mA.dcm.zip

@notZaki
Copy link
Member

notZaki commented Jul 26, 2024

Newer Siemens units use enhanced DICOM by default when exporting, and it looks like DICOM.jl struggles to read the deeply nested sequences in the header. So it trips up before reaching the pixel data.
I'll try to take a look as well.

Edit: On a closer look, the nested sequences are being parsed, so maybe it's a specific element in a sequence causing the issue.

@Dale-Black
Copy link
Contributor Author

Oh wow thank you for being so quick to respond. I appreciate you looking into this very much!

@notZaki
Copy link
Member

notZaki commented Jul 27, 2024

The current (unreleased) master tries to quickly/temporarily fix this.

I tried the following:

dcm = dcm_parse(path_70_kev)
rescale!(dcm)

# Using Plots
heatmap(dcm.PixelData, aspect_ratio=1, color=:grays, yflip=true, clim=(-1000, 2000), axis=false, grid=false)

and it approximately matches what I see in a dicom viewer. Let me know if it works for you.

@Dale-Black
Copy link
Contributor Author

Great, this works and has the correct pixel data!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants