Plotting a raster image

Hello,

Is there a Julia package to plot a raster image pixel by pixel? I mean I have a complex function f, say on a square, and for each point z of the square I want to plot f(z) as a color (with my own color mapping). Example (made with R):

using Images

# Construct the array of complex values.
z = (1:-0.01:-1) .* im .+ (-1:0.01:1)';

# Define the function z->RGB on each point
f(z) = RGB(abs(imag(z)), abs(angle(z)), abs(z))

# Broadcast the function.
image = f.(z)
1 Like

Thanks. And then one has to do plot(image)?

I think if you are using VSCode it will automatically display. I have ImageInTerminal installed, so I get a preview in the terminal. Images.jl exports imshow. You could also use one of the plotting packages, Makie or Plots.

FYI (may not be what you want), but Plots.heatmap() is a straightforward way to render (real) values of a 2-D array with a selectable (or definable) colormap. It’s similar to imagesc() in Matlab.

Thanks, this works. With Atom & Juno this also automatically plots the image. But there’s nothing to save it.

Images.save("myimage.png", image) is fine, but how to specify the width and the height in pixels?

To save the image at some resolution, resize it:

imgr = imresize(image, (m,n))
save("resized-image.png", imgr)
1 Like

Thanks. In view of your avatar, it seems you like elliptic/modular functions. Here is one:

Very fast with Julia, as usual.

1 Like