Read .img medical image without header in python

后端 未结 2 1846
情深已故
情深已故 2020-12-18 09:38

I have a radiograph .img file without the header file. However, the researchers who have published the file have given this information about it

High resolut         


        
相关标签:
2条回答
  • 2020-12-18 09:59

    Just in case anybody else is looking at these images and wants to convert them in batches, or outside of Python and without needing any programming knowledge... you can convert them pretty readily at the command line in Terminal with ImageMagick (which is installed on most Linux distros anyway, and available for OS X and Windows) like this:

    convert -size 2048x2048 -depth 16 -endian MSB -normalize gray:JPCLN130.IMG -compress lzw result.tif
    

    which makes them into compressed 16-bit TIF files that can be viewed in any application. They also then take up half the space on disk without loss of quality since I specified LZW compression.

    Likewise, if you want 16-bit PNG files, you can use:

    convert -size 2048x2048 -depth 16 -endian MSB -normalize gray:JPCLN130.IMG result.png
    

    0 讨论(0)
  • 2020-12-18 10:24

    I found some radiograph images, like yours, by downloading the JSRT database. I have tested the following code on the first image of this database: JPCLN001.IMG.

    import matplotlib.pyplot as plt
    import numpy as np
    
    # Parameters.
    input_filename = "JPCLN001.IMG"
    shape = (2048, 2048) # matrix size
    dtype = np.dtype('>u2') # big-endian unsigned integer (16bit)
    output_filename = "JPCLN001.PNG"
    
    # Reading.
    fid = open(input_filename, 'rb')
    data = np.fromfile(fid, dtype)
    image = data.reshape(shape)
    
    # Display.
    plt.imshow(image, cmap = "gray")
    plt.savefig(output_filename)
    plt.show()
    

    It produces an output file JPCLN001.PNG which looks like this:

    I hope I have answered to your question. Happy coding!

    0 讨论(0)
提交回复
热议问题