0
$\begingroup$

I have a square array with brightness data (Gaussian for this example). I convert it into a grayscale image with Image[]. But I would like to add color via ColorFunction which is why I rasterize it, but not only does that change the image size, it also changes the effective resolution and leads to some artifacts. Here is my code:

data = Table[
   Exp[-1/100 ((ix - 50)^2 + (iy - 50)^2)], {ix, 1, 100}, {iy, 1, 100}];
Export["img1.png", Image[data]];
Export["img2.png", 
  Graphics[Raster[data, ColorFunction -> "SolarColors"], 
   PlotRangePadding -> 0, ImagePadding -> 0, ImageSize -> 100]];

The two images are attached below (left: original grayscale, right: colorfunction'ed one). Not only does the processed image (img2.png) have a different resolution of 134x134, it seems to me that it also sufferend some compression artifacts.

How can I make sure the image quality in the processed image does not suffer?

img1.png img2.png

$\endgroup$
3
  • $\begingroup$ I just realized, using dataColored = Map[colorFunc, data, {2}]; and then Image[dataColored] does the trick. But I still don't know why the image generated with Raster has the wrong resolution. $\endgroup$ Commented Aug 6 at 13:15
  • $\begingroup$ You are supplying a Graphic to Export, so it is being re-rasterized. And ImageSize is not in pixels, it is in points. $\endgroup$ Commented Aug 6 at 13:50
  • $\begingroup$ Ah, I see! How can I set the pixel resolution at the Export level? $\endgroup$ Commented Aug 6 at 14:15

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.