yield frames and description from the segmentation image. This function is adapted from Highdicom: https://github.com/herrmannlab/highdicom/blob/v0.18.2/src/highdicom/seg/utils.py which has the following license... # ========================================
(self, img, filename, array_data)
| 771 | return affine |
| 772 | |
| 773 | def _get_frame_data(self, img, filename, array_data) -> Iterator: |
| 774 | """ |
| 775 | yield frames and description from the segmentation image. |
| 776 | This function is adapted from Highdicom: |
| 777 | https://github.com/herrmannlab/highdicom/blob/v0.18.2/src/highdicom/seg/utils.py |
| 778 | |
| 779 | which has the following license... |
| 780 | |
| 781 | # ========================================================================= |
| 782 | # https://github.com/herrmannlab/highdicom/blob/v0.18.2/LICENSE |
| 783 | # |
| 784 | # Copyright 2020 MGH Computational Pathology |
| 785 | # Permission is hereby granted, free of charge, to any person obtaining a |
| 786 | # copy of this software and associated documentation files (the |
| 787 | # "Software"), to deal in the Software without restriction, including |
| 788 | # without limitation the rights to use, copy, modify, merge, publish, |
| 789 | # distribute, sublicense, and/or sell copies of the Software, and to |
| 790 | # permit persons to whom the Software is furnished to do so, subject to |
| 791 | # the following conditions: |
| 792 | # The above copyright notice and this permission notice shall be included |
| 793 | # in all copies or substantial portions of the Software. |
| 794 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 795 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 796 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 797 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 798 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 799 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 800 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 801 | # ========================================================================= |
| 802 | |
| 803 | (https://github.com/herrmannlab/highdicom/issues/188) |
| 804 | |
| 805 | Args: |
| 806 | img: a Pydicom dataset object that has attribute "SegmentSequence". |
| 807 | |
| 808 | """ |
| 809 | |
| 810 | if not hasattr(img, "PerFrameFunctionalGroupsSequence"): |
| 811 | raise NotImplementedError(f"To read dicom seg: {filename}, 'PerFrameFunctionalGroupsSequence' is required.") |
| 812 | |
| 813 | frame_seg_nums = [] |
| 814 | for f in img.PerFrameFunctionalGroupsSequence: |
| 815 | if not hasattr(f, "SegmentIdentificationSequence"): |
| 816 | raise NotImplementedError( |
| 817 | f"To read dicom seg: {filename}, 'SegmentIdentificationSequence' is required for each frame." |
| 818 | ) |
| 819 | frame_seg_nums.append(int(f.SegmentIdentificationSequence[0].ReferencedSegmentNumber)) |
| 820 | |
| 821 | frame_seg_nums_arr = cp.array(frame_seg_nums) if self.to_gpu else np.array(frame_seg_nums) |
| 822 | |
| 823 | seg_descriptions = {int(f.SegmentNumber): f for f in img.SegmentSequence} |
| 824 | |
| 825 | for i in np.unique(frame_seg_nums_arr) if not self.to_gpu else cp.unique(frame_seg_nums_arr): |
| 826 | indices = np.where(frame_seg_nums_arr == i)[0] if not self.to_gpu else cp.where(frame_seg_nums_arr == i)[0] |
| 827 | yield (array_data[indices, ...], seg_descriptions[i]) |
| 828 | |
| 829 | def _get_seg_data(self, img, filename): |
| 830 | """ |
no test coverage detected