supervisely 6.73.334__py3-none-any.whl → 6.73.335__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -135,6 +135,28 @@ def create_pixel_data_set(dcm: FileDataset, frame_axis: int) -> Tuple[List[np.nd
135
135
  list_of_images = np.split(pixel_array, int(dcm.NumberOfFrames), axis=frame_axis)
136
136
  return list_of_images, frame_axis
137
137
 
138
+ def convert_to_monochrome2(dcm_path: str, dcm: FileDataset) -> FileDataset:
139
+ if getattr(dcm, "PhotometricInterpretation", None) == "YBR_FULL_422":
140
+ # * Convert dicom to monochrome
141
+ if len(dcm.pixel_array.shape) == 4 and dcm.pixel_array.shape[-1] == 3:
142
+ monochrome = dcm.pixel_array[..., 0].astype(np.uint8)
143
+ else:
144
+ logger.warn("Unexpected shape for YBR_FULL_422 data: " + str(dcm.pixel_array.shape))
145
+
146
+ try:
147
+ dcm.SamplesPerPixel = 1
148
+ dcm.PhotometricInterpretation = "MONOCHROME2"
149
+ dcm.PlanarConfiguration = 0
150
+ if len(monochrome.shape) == 3:
151
+ dcm.NumberOfFrames = str(monochrome.shape[0])
152
+ dcm.Rows, dcm.Columns = monochrome.shape[1:3]
153
+ dcm.PixelData = monochrome.tobytes()
154
+ except AttributeError as ae:
155
+ logger.error(f"Error occurred while converting dicom to monochrome: {ae}")
156
+
157
+ logger.info("Rewriting DICOM file with monochrome2 format")
158
+ dcm.save_as(dcm_path)
159
+ return dcm
138
160
 
139
161
  def convert_dcm_to_nrrd(
140
162
  image_path: str, converted_dir: str, group_tag_name: Optional[list] = None
@@ -147,6 +169,13 @@ def convert_dcm_to_nrrd(
147
169
  mkdir(curr_convert_dir)
148
170
 
149
171
  dcm = pydicom.read_file(image_path)
172
+ try:
173
+ if dcm.file_meta.TransferSyntaxUID.is_compressed:
174
+ dcm.decompress()
175
+ except AttributeError:
176
+ logger.warn("Couldn't find key 'TransferSyntaxUID' in dicom's metadata.")
177
+ dcm = convert_to_monochrome2(image_path, dcm)
178
+
150
179
  dcm_meta = get_dcm_meta(dcm)
151
180
 
152
181
  if group_tag_name is None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: supervisely
3
- Version: 6.73.334
3
+ Version: 6.73.335
4
4
  Summary: Supervisely Python SDK.
5
5
  Home-page: https://github.com/supervisely/supervisely
6
6
  Author: Supervisely
@@ -594,7 +594,7 @@ supervisely/convert/image/masks/image_with_masks_helper.py,sha256=TSHiAIH3qlYdjR
594
594
  supervisely/convert/image/masks/images_with_masks_converter.py,sha256=Won5LihYXZZmimgaJHmK0_rVmOadWYk21OHKri21R08,6866
595
595
  supervisely/convert/image/medical2d/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
596
596
  supervisely/convert/image/medical2d/medical2d_converter.py,sha256=cYEaRfr8YFxEG_Pv-_SVMxrqZudi3kWbGQ3aArL2mds,8156
597
- supervisely/convert/image/medical2d/medical2d_helper.py,sha256=pfLRCSFbFa5EIhmbB7kdmdWRu01OwIEDPXeNHzAeagg,12329
597
+ supervisely/convert/image/medical2d/medical2d_helper.py,sha256=UzZRJHtbTC7Tw-BIXaGrk3FhwPR-gglvHyVv2wio0Uw,13633
598
598
  supervisely/convert/image/multi_view/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
599
599
  supervisely/convert/image/multi_view/multi_view.py,sha256=V-6oFN6oDre7UhejfyDkGKAg4rbM3C9JCQ8pHhuUBb8,4436
600
600
  supervisely/convert/image/multispectral/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -1082,9 +1082,9 @@ supervisely/worker_proto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
1082
1082
  supervisely/worker_proto/worker_api_pb2.py,sha256=VQfi5JRBHs2pFCK1snec3JECgGnua3Xjqw_-b3aFxuM,59142
1083
1083
  supervisely/worker_proto/worker_api_pb2_grpc.py,sha256=3BwQXOaP9qpdi0Dt9EKG--Lm8KGN0C5AgmUfRv77_Jk,28940
1084
1084
  supervisely_lib/__init__.py,sha256=7-3QnN8Zf0wj8NCr2oJmqoQWMKKPKTECvjH9pd2S5vY,159
1085
- supervisely-6.73.334.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
1086
- supervisely-6.73.334.dist-info/METADATA,sha256=jD55cUT6bmdvsvTMuPD3Jt61Aus-DzBZciz5C5VO2HA,33596
1087
- supervisely-6.73.334.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
1088
- supervisely-6.73.334.dist-info/entry_points.txt,sha256=U96-5Hxrp2ApRjnCoUiUhWMqijqh8zLR03sEhWtAcms,102
1089
- supervisely-6.73.334.dist-info/top_level.txt,sha256=kcFVwb7SXtfqZifrZaSE3owHExX4gcNYe7Q2uoby084,28
1090
- supervisely-6.73.334.dist-info/RECORD,,
1085
+ supervisely-6.73.335.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
1086
+ supervisely-6.73.335.dist-info/METADATA,sha256=-Xv7Subzo7aabPOrXvxNbLXl9oIF6HIKstyMecAGzV0,33596
1087
+ supervisely-6.73.335.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
1088
+ supervisely-6.73.335.dist-info/entry_points.txt,sha256=U96-5Hxrp2ApRjnCoUiUhWMqijqh8zLR03sEhWtAcms,102
1089
+ supervisely-6.73.335.dist-info/top_level.txt,sha256=kcFVwb7SXtfqZifrZaSE3owHExX4gcNYe7Q2uoby084,28
1090
+ supervisely-6.73.335.dist-info/RECORD,,