简体   繁体   中英

Post-processing the heatmap in python or ImageMagick

How could I make this heatmap look more clear without the blurred effect. How could I sharpen it Python (or ImageMagick)? also, how could I get a pixel-grid on the background?

在此处输入图片说明

Here is what I used to get the current image:

maxsize = (1030, 2056)
for i in range(1,334,1):
    img = Image.open('C:Desktop/Img/image'+'_'+ str(i)+'.png')
    img = img.resize(maxsize, Image.BICUBIC)
    img.save('C:/Desktop/Res/img'+'_'+ str(i)+'.png', dpi = (7040,7040))

I also tried in ImageMagick (but that did not help much, atleast looking visually):

magick img_244.png -sharpen 0x3 out.png

Thank you very much in advance,

In ImageMagick (and also OpenCV/python) you can use kmeans to process your image. I have a bash unix shell script for ImageMagick that does that.

kmeans -n 7 -m 5 g4Zwf.png result7.png

where n is the number of colors and m is the maximum number of iterations.

在此处输入图片说明

Then you can use my script, grid, to draw lines (or use ImageMagick directly) to draw lines. Using my script, grid with 100 pixel spacing gives:

grid -s 100,100 -c white result7.png result7g100.png

在此处输入图片说明

My scripts are at http://www.fmwconcepts.com/imagemagick/index.html

For OpenCV/Python, see http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_ml/py_kmeans/py_kmeans_opencv/py_kmeans_opencv.html and How to write lines and grid on image in Python?

OpenCV/Python also has expectation maximization that may perform better on your color processing than kmeans. See https://en.wikipedia.org/wiki/Expectation–maximization_algorithm and Maximum likelihood pixel classification in python opencv

What module did you import as is Image ? What you need is a nearest neighbor interpolation, not bicubic interpolation . Probably something like

img = img.resize(maxsize, Image.INTER_NEAREST)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM