comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » color plot over greyscale image - postscript
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
color plot over greyscale image - postscript [message #70924] Fri, 21 May 2010 15:04 Go to next message
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
Hi all,

I'm having problems mixing images and plots in postscript. What I
want is to display a greyscale image, then overplot a number of
differently colored points at designated pixel values. What I'm
currently doing is setting up plot axes first with plot, /nodata, x/
ystyle=8, position=[0,0,1,1]. Then, I use Coyote's TVImage, /overplot
to fit the image inside the plot axes, and then oplot to put in the
points. The problems are:
1) Even with TVImage, it seems like the alignment of the plot axes and
the image is off. All the points reside in the box approximately
[0,0,.75,.75].
2) When the points I oplot are red, the greyscale works fine. Any
other color causes the greyscale to be filled with seemingly randomly
distributed colored pixels.

The answer is probably something simple like decompose=0 or loading
color tables intelligently, but I just can't seem to get my mind
around this right now. Any advice would be greatly appreciated.

--Gray
Re: color plot over greyscale image - postscript [message #71041 is a reply to message #70924] Mon, 24 May 2010 19:37 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Gray writes:

> Hey David, did you know that you are all three of the top 3 posters
> all time on this group?

Well, I'm shocked. But my wife says, "Duh!"

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: color plot over greyscale image - postscript [message #71042 is a reply to message #70924] Mon, 24 May 2010 19:27 Go to previous message
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
On May 24, 5:18 pm, David Fanning <n...@dfanning.com> wrote:
> Gray writes:
>> Correct on all counts!  I added loadct, 0, /silent after set_plot,
>> 'ps', then went back to declaring my axes beforehand with plot, /
>> nodata, x/ystyle=9 and tvimage, /overplot.  I think my original
>> problem was that I had called fsc_color before running my tvimage.
>
> Yes, it is probably worth saying one more time. Load the colors
> you plan to use JUST BEFORE you plan to use them. :-)
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thue. ("Perhaps thos speakest truth.")

Hey David, did you know that you are all three of the top 3 posters
all time on this group?
Re: color plot over greyscale image - postscript [message #71043 is a reply to message #70924] Mon, 24 May 2010 14:18 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Gray writes:

> Correct on all counts! I added loadct, 0, /silent after set_plot,
> 'ps', then went back to declaring my axes beforehand with plot, /
> nodata, x/ystyle=9 and tvimage, /overplot. I think my original
> problem was that I had called fsc_color before running my tvimage.

Yes, it is probably worth saying one more time. Load the colors
you plan to use JUST BEFORE you plan to use them. :-)

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
Re: color plot over greyscale image - postscript [message #71044 is a reply to message #70924] Mon, 24 May 2010 14:13 Go to previous message
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
On May 24, 4:50 pm, David Fanning <n...@dfanning.com> wrote:
> Gray writes:
>> Okay, still not working, but in a different way.  I tried to do this
>> systematically, doing a .RESET to clear everything.  Here's my code
>> (using random x and y values for the overplot):
>
>> set_plot, 'ps'
>> img = readfits('myimage.fits')
>> img_sz = size(img,/dim)
>> keywords = psconfig(/nogui,/encapsul,/color,/inches,xsize=6,$
>>   ysize=6.*img_sz[0]/img_sz[1],filename='myimage.eps')
>> device, _extra=keywords
>> tvimage, img, /axes, axkey={xstyle:9,ystyle:9}, $
>>   xra=[0,img_sz[0]-1], yra=[0,img_sz[1]-1]
>> x = randomu(seed,100)*(img_sz[0]-1)
>> y = randomu(seed,100)*(img_sz[1]-1)
>> loadct, 13, /silent
>> oplot, x, y, psym=4, color=fsc_color('green')
>> oplot, x+1,y+1,psym=1, color=fsc_color('red')
>> oplot, x-1,y-1,psym=6, color=fsc_color('yellow')
>> device, /close
>> set_plot, 'x'
>
>> When I do this, I have two problems:  1) my points (if they overplot
>> at all, I'm not 100% convinced) are in greyscale, even though I loaded
>> a new color table, and 2) I've now realized that even passing those
>> black against the border of a complicated greyscale image, but it's
>> there.
>
> OK, no grey-scale color table is loaded before
> you display the image. So whatever colors happen
> to be loaded, will be what the image uses.
>
> Then, if you are going to use FSC_COLOR for the
> overlay colors, there is no need to load a color
> table before you draw your overlays. FSC_COLOR
> will load its own color in the color table before
> it does the drawing. (And it will dirty the one
> and only color table, which is why you have to
> refresh it BEFORE you display your image!)
>
> If your points are overlaying (only you can tell
> this for sure), I can assure you they are NOT
> overlaying with gray-scale colors. FSC_COLOR has
> worked for a *long* time. It is *extremely* unlikely
> that it would be broken, expecially with the colors
> "red", "green" and "yellow". It's more likely that
> you aren't drawing in a data space you think you
> are drawing into.
>
> What happened to your plot command? I thought that
> was how you were setting up the data space? TVImage
> may look to you like it is "doing the right thing",
> but it is actually designed to "do the same wrong
> thing the TV command does". That is to say, it will
> not establish a data coordinate system on its own.
> It seems to me the data "space" where you are drawing
> your overplots is probably in some random data space
> in which you accidentally drew a plot in your IDL
> session.
>
> I'd go back to the PLOT command, put your image on it,
> then try to draw into it.
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thue. ("Perhaps thos speakest truth.")

Correct on all counts! I added loadct, 0, /silent after set_plot,
'ps', then went back to declaring my axes beforehand with plot, /
nodata, x/ystyle=9 and tvimage, /overplot. I think my original
problem was that I had called fsc_color before running my tvimage.
Re: color plot over greyscale image - postscript [message #71045 is a reply to message #70924] Mon, 24 May 2010 13:50 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Gray writes:

> Okay, still not working, but in a different way. I tried to do this
> systematically, doing a .RESET to clear everything. Here's my code
> (using random x and y values for the overplot):
>
> set_plot, 'ps'
> img = readfits('myimage.fits')
> img_sz = size(img,/dim)
> keywords = psconfig(/nogui,/encapsul,/color,/inches,xsize=6,$
> ysize=6.*img_sz[0]/img_sz[1],filename='myimage.eps')
> device, _extra=keywords
> tvimage, img, /axes, axkey={xstyle:9,ystyle:9}, $
> xra=[0,img_sz[0]-1], yra=[0,img_sz[1]-1]
> x = randomu(seed,100)*(img_sz[0]-1)
> y = randomu(seed,100)*(img_sz[1]-1)
> loadct, 13, /silent
> oplot, x, y, psym=4, color=fsc_color('green')
> oplot, x+1,y+1,psym=1, color=fsc_color('red')
> oplot, x-1,y-1,psym=6, color=fsc_color('yellow')
> device, /close
> set_plot, 'x'
>
> When I do this, I have two problems: 1) my points (if they overplot
> at all, I'm not 100% convinced) are in greyscale, even though I loaded
> a new color table, and 2) I've now realized that even passing those
> black against the border of a complicated greyscale image, but it's
> there.

OK, no grey-scale color table is loaded before
you display the image. So whatever colors happen
to be loaded, will be what the image uses.

Then, if you are going to use FSC_COLOR for the
overlay colors, there is no need to load a color
table before you draw your overlays. FSC_COLOR
will load its own color in the color table before
it does the drawing. (And it will dirty the one
and only color table, which is why you have to
refresh it BEFORE you display your image!)

If your points are overlaying (only you can tell
this for sure), I can assure you they are NOT
overlaying with gray-scale colors. FSC_COLOR has
worked for a *long* time. It is *extremely* unlikely
that it would be broken, expecially with the colors
"red", "green" and "yellow". It's more likely that
you aren't drawing in a data space you think you
are drawing into.

What happened to your plot command? I thought that
was how you were setting up the data space? TVImage
may look to you like it is "doing the right thing",
but it is actually designed to "do the same wrong
thing the TV command does". That is to say, it will
not establish a data coordinate system on its own.
It seems to me the data "space" where you are drawing
your overplots is probably in some random data space
in which you accidentally drew a plot in your IDL
session.

I'd go back to the PLOT command, put your image on it,
then try to draw into it.

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
Re: color plot over greyscale image - postscript [message #71046 is a reply to message #70924] Mon, 24 May 2010 13:21 Go to previous message
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
On May 24, 4:00 pm, David Fanning <n...@dfanning.com> wrote:
> Gray writes:
>> So, I looked at TVIMAGE more closely and realized that passing x/
>> ystyle=9 with the /AXES keyword (and others) works exactly the way I
>> want.  However, I'm still having an issue with the color thing.  I
>> have IDL 7.0, so I can't set decomposed=1 for a postscript device, and
>> TVIMAGE doesn't let me pass {true:1} as _extra, because it requires a
>> 3D array.  Any suggestions besides updating IDL to 7.1 (which I'll do
>> if it's my only option)?
>
> Well, if I load the colors I want to use *just before
> I want to use them*, I have never had any trouble getting
> the colors I wanted. Are you doing something other than
> this?
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thue. ("Perhaps thos speakest truth.")

Okay, still not working, but in a different way. I tried to do this
systematically, doing a .RESET to clear everything. Here's my code
(using random x and y values for the overplot):

set_plot, 'ps'
img = readfits('myimage.fits')
img_sz = size(img,/dim)
keywords = psconfig(/nogui,/encapsul,/color,/inches,xsize=6,$
ysize=6.*img_sz[0]/img_sz[1],filename='myimage.eps')
device, _extra=keywords
tvimage, img, /axes, axkey={xstyle:9,ystyle:9}, $
xra=[0,img_sz[0]-1], yra=[0,img_sz[1]-1]
x = randomu(seed,100)*(img_sz[0]-1)
y = randomu(seed,100)*(img_sz[1]-1)
loadct, 13, /silent
oplot, x, y, psym=4, color=fsc_color('green')
oplot, x+1,y+1,psym=1, color=fsc_color('red')
oplot, x-1,y-1,psym=6, color=fsc_color('yellow')
device, /close
set_plot, 'x'

When I do this, I have two problems: 1) my points (if they overplot
at all, I'm not 100% convinced) are in greyscale, even though I loaded
a new color table, and 2) I've now realized that even passing those
xstyle keywords don't suppress the axis. It's subtle, because it's
black against the border of a complicated greyscale image, but it's
there.
Re: color plot over greyscale image - postscript [message #71047 is a reply to message #70924] Mon, 24 May 2010 13:10 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
David Fanning writes:

> Well, if I load the colors I want to use *just before
> I want to use them*, I have never had any trouble getting
> the colors I wanted. Are you doing something other than
> this?

Let me put this another way. Are you loading the gray-scale
color table just before you display the image?

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
Re: color plot over greyscale image - postscript [message #71048 is a reply to message #70924] Mon, 24 May 2010 13:00 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Gray writes:

> So, I looked at TVIMAGE more closely and realized that passing x/
> ystyle=9 with the /AXES keyword (and others) works exactly the way I
> want. However, I'm still having an issue with the color thing. I
> have IDL 7.0, so I can't set decomposed=1 for a postscript device, and
> TVIMAGE doesn't let me pass {true:1} as _extra, because it requires a
> 3D array. Any suggestions besides updating IDL to 7.1 (which I'll do
> if it's my only option)?

Well, if I load the colors I want to use *just before
I want to use them*, I have never had any trouble getting
the colors I wanted. Are you doing something other than
this?

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
Re: color plot over greyscale image - postscript [message #71049 is a reply to message #70924] Mon, 24 May 2010 12:54 Go to previous message
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
On May 23, 12:01 pm, David Fanning <n...@dfanning.com> wrote:
> Gray writes:
>> I'm having problems mixing images and plots in postscript.  What I
>> want is to display a greyscale image, then overplot a number of
>> differently colored points at designated pixel values.  What I'm
>> currently doing is setting up plot axes first with plot, /nodata, x/
>> ystyle=8, position=[0,0,1,1].  Then, I use Coyote's TVImage, /overplot
>> to fit the image inside the plot axes, and then oplot to put in the
>> points.  The problems are:
>> 1) Even with TVImage, it seems like the alignment of the plot axes and
>> the image is off.  All the points reside in the box approximately
>> [0,0,.75,.75].
>> 2) When the points I oplot are red, the greyscale works fine.  Any
>> other color causes the greyscale to be filled with seemingly randomly
>> distributed colored pixels.
>
>> The answer is probably something simple like decompose=0 or loading
>> color tables intelligently, but I just can't seem to get my mind
>> around this right now.  
>
> No, the answer *never* involves DECOMPOSE=0. :-)
>
> I wish people would just forget about indexed color, and
> maybe with IDL 8 they will.
>
> I can't tell from the clues you give exactly what you
> are doing incorrectly, but there are two good possibilities.
> First, if you are trying to match an image with plot
> axes you do not EVER want to let IDL set the endpoints
> of the axis. In other words, you want EXACT axis scaling.
> So those XStyle and YStyle keywords will have to have their
> first bit set. Probably you want to set these keywords
> to 8 + 1 or 9, rather than 8.
>
> The second thing you are probably doing incorrectly
> is using indexed color. ;-)
>
> If you want to do this, then you have to make *absolutely*
> sure you load the colors you want to use *just before* you
> want to use them. (Well, this is pretty much a requirement
> all the time.) I don't see you loading any color tables,
> and the fact that red dots appear in your image when you
> display it tells me you have a "dirty" color table at the
> time you displayed your image. In other words, load that
> gray scale color table just before you display the image,
> then load your drawing colors to draw on top of the image.
>
> If I were doing this, I would draw on top of the image
> with 24-bit colors (using DECOMPOSED=1 and FSC_COLOR)
> so I didn't have to worry about actually loading drawing
> colors, but then I pretty much never use indexed color. :-)
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

(By the way, I'm using PSCONFIG to set up my postscript device, so
generally, whatever that sets up is what my settings are.)
Re: color plot over greyscale image - postscript [message #71050 is a reply to message #70924] Mon, 24 May 2010 12:51 Go to previous message
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
On May 23, 12:01 pm, David Fanning <n...@dfanning.com> wrote:
> Gray writes:
>> I'm having problems mixing images and plots in postscript.  What I
>> want is to display a greyscale image, then overplot a number of
>> differently colored points at designated pixel values.  What I'm
>> currently doing is setting up plot axes first with plot, /nodata, x/
>> ystyle=8, position=[0,0,1,1].  Then, I use Coyote's TVImage, /overplot
>> to fit the image inside the plot axes, and then oplot to put in the
>> points.  The problems are:
>> 1) Even with TVImage, it seems like the alignment of the plot axes and
>> the image is off.  All the points reside in the box approximately
>> [0,0,.75,.75].
>> 2) When the points I oplot are red, the greyscale works fine.  Any
>> other color causes the greyscale to be filled with seemingly randomly
>> distributed colored pixels.
>
>> The answer is probably something simple like decompose=0 or loading
>> color tables intelligently, but I just can't seem to get my mind
>> around this right now.  
>
> No, the answer *never* involves DECOMPOSE=0. :-)
>
> I wish people would just forget about indexed color, and
> maybe with IDL 8 they will.
>
> I can't tell from the clues you give exactly what you
> are doing incorrectly, but there are two good possibilities.
> First, if you are trying to match an image with plot
> axes you do not EVER want to let IDL set the endpoints
> of the axis. In other words, you want EXACT axis scaling.
> So those XStyle and YStyle keywords will have to have their
> first bit set. Probably you want to set these keywords
> to 8 + 1 or 9, rather than 8.
>
> The second thing you are probably doing incorrectly
> is using indexed color. ;-)
>
> If you want to do this, then you have to make *absolutely*
> sure you load the colors you want to use *just before* you
> want to use them. (Well, this is pretty much a requirement
> all the time.) I don't see you loading any color tables,
> and the fact that red dots appear in your image when you
> display it tells me you have a "dirty" color table at the
> time you displayed your image. In other words, load that
> gray scale color table just before you display the image,
> then load your drawing colors to draw on top of the image.
>
> If I were doing this, I would draw on top of the image
> with 24-bit colors (using DECOMPOSED=1 and FSC_COLOR)
> so I didn't have to worry about actually loading drawing
> colors, but then I pretty much never use indexed color. :-)
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")

Thank you!

So, I looked at TVIMAGE more closely and realized that passing x/
ystyle=9 with the /AXES keyword (and others) works exactly the way I
want. However, I'm still having an issue with the color thing. I
have IDL 7.0, so I can't set decomposed=1 for a postscript device, and
TVIMAGE doesn't let me pass {true:1} as _extra, because it requires a
3D array. Any suggestions besides updating IDL to 7.1 (which I'll do
if it's my only option)?
Re: color plot over greyscale image - postscript [message #71064 is a reply to message #70924] Sun, 23 May 2010 09:01 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Gray writes:

> I'm having problems mixing images and plots in postscript. What I
> want is to display a greyscale image, then overplot a number of
> differently colored points at designated pixel values. What I'm
> currently doing is setting up plot axes first with plot, /nodata, x/
> ystyle=8, position=[0,0,1,1]. Then, I use Coyote's TVImage, /overplot
> to fit the image inside the plot axes, and then oplot to put in the
> points. The problems are:
> 1) Even with TVImage, it seems like the alignment of the plot axes and
> the image is off. All the points reside in the box approximately
> [0,0,.75,.75].
> 2) When the points I oplot are red, the greyscale works fine. Any
> other color causes the greyscale to be filled with seemingly randomly
> distributed colored pixels.
>
> The answer is probably something simple like decompose=0 or loading
> color tables intelligently, but I just can't seem to get my mind
> around this right now.

No, the answer *never* involves DECOMPOSE=0. :-)

I wish people would just forget about indexed color, and
maybe with IDL 8 they will.

I can't tell from the clues you give exactly what you
are doing incorrectly, but there are two good possibilities.
First, if you are trying to match an image with plot
axes you do not EVER want to let IDL set the endpoints
of the axis. In other words, you want EXACT axis scaling.
So those XStyle and YStyle keywords will have to have their
first bit set. Probably you want to set these keywords
to 8 + 1 or 9, rather than 8.

The second thing you are probably doing incorrectly
is using indexed color. ;-)

If you want to do this, then you have to make *absolutely*
sure you load the colors you want to use *just before* you
want to use them. (Well, this is pretty much a requirement
all the time.) I don't see you loading any color tables,
and the fact that red dots appear in your image when you
display it tells me you have a "dirty" color table at the
time you displayed your image. In other words, load that
gray scale color table just before you display the image,
then load your drawing colors to draw on top of the image.

If I were doing this, I would draw on top of the image
with 24-bit colors (using DECOMPOSED=1 and FSC_COLOR)
so I didn't have to worry about actually loading drawing
colors, but then I pretty much never use indexed color. :-)

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Help with envi_output_to_external_file
Next Topic: Sodium Phosphide Formula

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:48:49 PDT 2025

Total time taken to generate the page: 0.00872 seconds