Adam Merckx
Adam Merckx

Reputation: 1214

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?

enter image description here

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,

Upvotes: 0

Views: 572

Answers (2)

fmw42
fmw42

Reputation: 53081

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.

enter image description here

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

enter image description here

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

Upvotes: 1

LUB
LUB

Reputation: 141

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)

Upvotes: 0

Related Questions