imViewer_Simple.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:augment3D 作者: yulkang 项目源码 文件源码
def loadPIL_LUT(self, dataset):
        if not have_PIL:
            raise ImportError("Python Imaging Library is not available. See http://www.pythonware.com/products/pil/ to download and install")
        if('PixelData' not in dataset):
            raise TypeError("Cannot show image -- DICOM dataset does not have pixel data")
        if('WindowWidth' not in dataset) or ('WindowCenter' not in dataset):  # can only apply LUT if these values exist
            bits = dataset.BitsAllocated
            samples = dataset.SamplesPerPixel
            if bits == 8 and samples == 1:
                mode = "L"
            elif bits == 8 and samples == 3:
                mode = "RGB"
            elif bits == 16:  # not sure about this -- PIL source says is 'experimental' and no documentation.
                mode = "I;16"  # Also, should bytes swap depending on endian of file and system??
            else:
                raise TypeError("Don't know PIL mode for %d BitsAllocated and %d SamplesPerPixel" % (bits, samples))
            size = (dataset.Columns, dataset.Rows)
            im = PIL.Image.frombuffer(mode, size, dataset.PixelData, "raw", mode, 0, 1)  # Recommended to specify all details by http://www.pythonware.com/library/pil/handbook/image.htm
        else:
            image = self.get_LUT_value(dataset.pixel_array, dataset.WindowWidth, dataset.WindowCenter)
            im = PIL.Image.fromarray(image).convert('L')  # Convert mode to L since LUT has only 256 values: http://www.pythonware.com/library/pil/handbook/image.htm
        return im
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号