Commit c4a14aa34a15a3c4719507ffd4eb54025a226477

Authored by Thiago Franco de Moraes
1 parent d9daf157
Exists in master

Handling 1bit pixel dicom images

Showing 1 changed file with 3 additions and 0 deletions   Show diff stats
invesalius/data/converters.py
... ... @@ -149,6 +149,7 @@ def np_rgba_to_vtk(n_array, spacing=(1.0, 1.0, 1.0)):
149 149 # Based on http://gdcm.sourceforge.net/html/ConvertNumpy_8py-example.html
150 150 def gdcm_to_numpy(image, apply_intercep_scale=True):
151 151 map_gdcm_np = {
  152 + gdcm.PixelFormat.SINGLEBIT: np.uint8,
152 153 gdcm.PixelFormat.UINT8: np.uint8,
153 154 gdcm.PixelFormat.INT8: np.int8,
154 155 gdcm.PixelFormat.UINT12: np.uint16,
... ... @@ -177,6 +178,8 @@ def gdcm_to_numpy(image, apply_intercep_scale=True):
177 178 np_array = np.frombuffer(
178 179 gdcm_array.encode("utf-8", errors="surrogateescape"), dtype=dtype
179 180 )
  181 + if pf.GetScalarType() == gdcm.PixelFormat.SINGLEBIT:
  182 + np_array = np.unpackbits(np_array)
180 183 np_array.shape = shape
181 184 np_array = np_array.squeeze()
182 185  
... ...