Repository: Project-MONAI/MONAI

Issue:
Get an error when reading dicom segmentation
**Describe the bug**
When I tried to read the dicom segmentation label with LoadImage in MONAI transforms, it reported a bug shown below.

```
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/venv/lib/python3.11/site-packages/monai/transforms/io/array.py", line 290, in __call__
    img_array, meta_data = reader.get_data(img)
                           ^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/monai/data/image_reader.py", line 586, in get_data
    data_array, metadata = self._get_seg_data(d)
                           ^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/monai/data/image_reader.py", line 770, in _get_seg_data
    class_name = description.SegmentDescription
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/pydicom/dataset.py", line 908, in __getattr__
    return object.__getattribute__(self, name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Dataset' object has no attribute 'SegmentDescription'
```

**To Reproduce**
Steps to reproduce the behavior:
1. Install the MONAI main branch.
2. Download the attachment [dcm file](https://drive.google.com/file/d/13_-1weQkBlkbcMzWixqKUDCGBs1lu2oq/view?usp=sharing) whose md5 is f511acb750076c56ad2d9647dcfe521d.
3. Run command `python -c "from monai.transforms import LoadImage; loader = LoadImage(reader='pydicomreader'); loader('./SE000000.dcm');"`
4.  If I changed [this line](https://github.com/Project-MONAI/MONAI/blob/e48c3e2c741fa3fc705c4425d17ac4a5afac6c47/monai/data/image_reader.py#L769) to `class_name = description.SegmentDescription if hasattr(description, "SegmentDescription") else description.SegmentLabel`, it works. However I am not sure if this modification is good enough.

**Expected behavior**
Read segmentation correctly.

Get an error when reading dicom segmentation
**Describe the bug**
When I tried to read the dicom segmentation label with LoadImage in MONAI transforms, it reported a bug shown below.

```
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/venv/lib/python3.11/site-packages/monai/transforms/io/array.py", line 290, in __call__
    img_array, meta_data = reader.get_data(img)
                           ^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/monai/data/image_reader.py", line 586, in get_data
    data_array, metadata = self._get_seg_data(d)
                           ^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/monai/data/image_reader.py", line 770, in _get_seg_data
    class_name = description.SegmentDescription
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/pydicom/dataset.py", line 908, in __getattr__
    return object.__getattribute__(self, name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Dataset' object has no attribute 'SegmentDescription'
```

**To Reproduce**
Steps to reproduce the behavior:
1. Install the MONAI main branch.
2. Download the attachment [dcm file](https://drive.google.com/file/d/13_-1weQkBlkbcMzWixqKUDCGBs1lu2oq/view?usp=sharing) whose md5 is f511acb750076c56ad2d9647dcfe521d.
3. Run command `python -c "from monai.transforms import LoadImage; loader = LoadImage(reader='pydicomreader'); loader('./SE000000.dcm');"`
4.  If I changed [this line](https://github.com/Project-MONAI/MONAI/blob/e48c3e2c741fa3fc705c4425d17ac4a5afac6c47/monai/data/image_reader.py#L769) to `class_name = description.SegmentDescription if hasattr(description, "SegmentDescription") else description.SegmentLabel`, it works. However I am not sure if this modification is good enough.

**Expected behavior**
Read segmentation correctly.



Discussion:
cc @SachidanandAlle , @tangy5 for reference.
it seems `SegmentLabel` is a required attribute and `SegmentDescription` is optional, perhaps the logic should be try `SegmentLabel` first
cc @SachidanandAlle , @tangy5 for reference.
it seems `SegmentLabel` is a required attribute and `SegmentDescription` is optional, perhaps the logic should be try `SegmentLabel` first

Resolving patch:
diff --git a/monai/data/image_reader.py b/monai/data/image_reader.py
--- a/monai/data/image_reader.py
+++ b/monai/data/image_reader.py
@@ -766,7 +766,8 @@ def _get_seg_data(self, img):
             all_segs = np.zeros([*spatial_shape, n_classes])
 
         for i, (frames, description) in enumerate(self._get_frame_data(img)):
-            class_name = description.SegmentDescription
+            segment_label = getattr(description, "SegmentLabel", f"label_{i}")
+            class_name = getattr(description, "SegmentDescription", segment_label)
             if class_name not in metadata["labels"].keys():
                 metadata["labels"][class_name] = i
             class_num = metadata["labels"][class_name]


Test patch: