[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
ind2rgb and pngwrite (was "xvloadimage with imagesc and colormap")
From: |
Mike Miller |
Subject: |
ind2rgb and pngwrite (was "xvloadimage with imagesc and colormap") |
Date: |
Thu, 9 Mar 2006 17:22:25 -0600 (CST) |
On Wed, 8 Mar 2006, Stefan van der Walt wrote:
Mike Miller wrote:
If I want to save an imagesc() image to a file, what do I have to do?
It isn't using gnuplot, so the usual __gnuplot_set__ methods don't
work.
Use the `ind2rgb' function to convert your indexed image to RGB, after
which you can use `imwrite' (`jpgwrite' or `pngwrite') to store the
image to a file.
In case it matters, I'm running Octave 2.1.71 under Linux with Octave
Forge and I don't have xv or ImageMagick installed, but I do have
xloadimage.
Without ImageMagick you will have to rely on `jpgwrite` or `pngwrite`.
This was excellent advice, but I think I should add something to help
people like me who are dealing with these functions for the first time.
Here are the two help docs:
- Function File: [R, G, B] = ind2rgb (X, MAP)
Convert an indexed image to red, green, and blue color components.
If MAP is omitted, the current colormap is used for the conversion.
pngwrite writes a png file to the disk.
pngwrite('filename',R,G,B,A) writes the specified file
using the Red, Green, Blue and Alpha matrices.
Data must be [0 255] or the high bytes will be lost.
My MAP used [0,1] values, so the R,G,B values were all [0,1], but it seems
that pngwrite requires [0,255] instead. Also, my X matrix was [0,1], and
it seems that it has to be [1,256]. So I did this and it seemed to work
for me:
[R, G, B] = ind2rgb( round( 255*X ) + 1, round( 255*MAP ) );
But I didn't know what an "Alpha matrix" was for pngwrite, so I tried a
few things and ended up finding that this seemed to work:
A = round( 255 * ones( size(X) ) );
pngwrite( 'file.png', R, G, B, A)
The resulting png file looked good, but I'm not sure that I was following
correct procedure and I would enjoy hearing from someone who knows better.
Thanks again for the helpful tips.
Mike
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------