Read .img medical image without header in python

后端 未结 2 1852
情深已故
情深已故 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条回答
  •  旧时难觅i
    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!

提交回复
热议问题