Previous Up Next

28.1.5  Exporting images

The writergb command writes images to PNG files. The image can be either an image object or given by the full Xcas legacy image structure (see Section 28.1.1, this is what is read in with readrgb) or a simplified version of this structure.

Examples

With image objects.

Assuming that the img variable contains an image object created with the image command (see Section 28.1.2), input:

writergb("image.png",img)
     
1           
With the legacy format.

Assume that the variable a represents a legacy image structure loaded from the file image1234.jpg by using readrgb (see the example in Section 28.1.3). Then:

writergb("image2134.png",[a[0],a[2],a[1],a[3],a[4]])

The image file image2134.png is thus created. This image is simply the image1234.png image with the green and red colors switched.

In simpler cases, you can type the Xcas image format in by hand.

writergb("image1.png",[[4,2,2],[[255,0],[0,0]],[[0,255],[0,0]], [[255,125],[255,255]],[[0,0],[255,0]]])

The transparency value of 125 for the upper right point makes it partially transparent and mutes the color. Observe that individual pixels are shown as rectangles due to the automatic scaling.

For larger images, in some cases the matrix operations of Xcas can be used to create the channels. The following command line creates the file image2.png containing the image shown below (the view is orthonormalized).

writergb("image2.png",[[4,30,30],makemat(0,30,30),makemat(0,30,30), makemat(255,30,30),makemat(0,30,30)+idn(30)*255])
Writing images with simplified image description.

The simplified version of the Xcas image description does not involve stating the number of channels, the size of the image, or the transparency. There is a full color version of this simplified form and a grayscale version.

Examples

writergb("image3.png",[[255,250],[0,120]],[[0,255],[0,0]],[[0,0],[255,100]])
writergb("image4.png",[[65,125],[185,200]])

Previous Up Next