Psconvert

I converted a grayscale diagram drawn by the psxy command to a BMP file by the psconvert command and converted the BMP file into a text file. I found that the number indicating the color had changed slightly. For example, the part drawn with -G16 in psxy command turned to 20 in bmp text file. The part drawn with -G80 in psxy command turned to 99. What should I do to ensure that the color does not change?

Not reproducible here. I did

echo 0 0 | gmt plot -Sc0.5c -G80 -R-1/1/-1/1 -JX1c -bmp t

and opened t.bmp in Adobe Photoshop and it says the gray color is 80. Perhaps your conversion is no good?

Thank you for testing a short code for me.
It seems you use GMT6 and you directly generate bmp file without converting from PS file.

I am using GMT5 and don’t know if I can directly generate bmp file with GMT5. I could not find such a way.

  1. First I did with GMT5 like this.
    set post = pwessel.ps
    echo 0 0 | gmt psxy -Sc0.5c -G80 -R-1/1/-1/1 -JX1c -K > $post
    echo 1 0 | gmt psxy -Sc0.5c -G80 -R -J -O >> $post
    gmt psconvert $post -Tb -E100 -A+s20i -P -I

  2. Then I read bmp file with python matplotlib module to get the values in text style as follows.
    import matplotlib.pyplot as plt
    lgray = plt.imread(‘pwessel.bmp’)
    print lgray

I get the value 99 for the area originally drawn as 80. It seems psconvert changes the color when converting.

Well, I cannot use GMT 5 as obsolete years ago, but otherwise I can run your sequence of commands. Again shows 80 in Adobe Photoshop.
The other source may be ghostscript since it is doing the actual conversion. My gs is 9.54.0.
It is possible that GMT 5 had a bug that has long been fixed or that the bug was in ghostscript, but at the present I can see no such problems.
GMT 5 is pretty old - you should upgrade - 6.2.0 just came out in June.

Thank you for the explanation of possible causes. I understand.

Installing GMT from source code on my Linux machines is always troublesome. I have tried many times and succeeded in only a few times. I tried to install GMT6, too, though failed. GMT5 was finally installed with ‘yum install’ just a few months ago…

Are you using Fedora or CentOS? If so, you can try to use the GMT RPM repository.

Install latest GMT on Fedora · GenericMappingTools/gmt Wiki (github.com)

Install latest GMT on RHEL CentOS · GenericMappingTools/gmt Wiki (github.com)

I am using CentOS. Thank you for this information!! I’ll try!