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

Home » Public Forums » archive » Re: making a circle of certain values
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
Re: making a circle of certain values [message #56106] Wed, 03 October 2007 01:42
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
David Fanning <david@dfanning.com> writes:
> rpertaub@gmail.com writes:
>
>> I have a set of data points (x,y coordinates) that can be plotted on
>> my 1240,1024 array. However, they are sparse x,y spots across the
>> image, and I want to 'thicken' it by drawing a circle with my x,y as
>> centers. I want to give it a certain radius and a certain value too,
>> so that the pixels in the circle (the filling) have values and can
>> thus contribute to my rgb image...
>> anyone know how to draw a circle, and assign a value to pixels within
>> that circle?
>
> I'd use the most useful routine I ever downloaded from the NASA
> Astronomy library: TVCIRCLE.
>
> You will probably have to write a new output keyword for that routine
> to recover the XY locations of the polygon it creates for the circle.
> Then use POLYFILLV to find the indices of the image inside that polygon.
>

Hmm, I just use this all the time:

pro circsym, _EXTRA=extra
theta=findgen(26)*0.251327412
xsym=cos(theta)
ysym=sin(theta)
usersym, xsym, ysym, _EXTRA=extra
return
end

either with CIRCSYM by itself, or CIRCSYM, /FILL, and then I'm ready
to plot with PSYM=8 and whatever SYMSIZE I want. And the circles stay
round!

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: making a circle of certain values [message #56121 is a reply to message #56106] Tue, 02 October 2007 09:33 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Loren Anderson writes:

> Too true. tvcircle is a great routine, but I do like having access to
> the data points.

Twenty seconds with a sharp editor should do 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 thui. ("Perhaps thou speakest truth.")
Re: making a circle of certain values [message #56122 is a reply to message #56121] Tue, 02 October 2007 09:30 Go to previous message
Loren Anderson is currently offline  Loren Anderson
Messages: 22
Registered: August 2007
Junior Member
> What is different about TVCIRCLE, however, is that it
> *always* produces circles on a plot, as opposed to this
> code, which might well produce ellipses if you have the
> plot aspect ratio as something other than 1:1.

Too true. tvcircle is a great routine, but I do like having access to
the data points.

-Loren
Re: making a circle of certain values [message #56123 is a reply to message #56122] Tue, 02 October 2007 08:43 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Loren Anderson writes:

> I'm not sure if this is what you need, but here are the guts of the
> tvcircle routine that David suggested:
>
> FUNCTION Circle, radius, xcenter, ycenter, NPoints=NPoints
> ; Returns the x and y values of a circle
>
> IF N_Elements(NPoints) EQ 0 THEN NPoints=100
>
> seeds = Findgen(npoints)/(npoints-1)*2*!pi
> xvals = sin(seeds)*radius+xcenter
> yvals = cos(seeds)*radius+ycenter
>
> RETURN, Transpose([[xvals], [yvals]])
> END

What is different about TVCIRCLE, however, is that it
*always* produces circles on a plot, as opposed to this
code, which might well produce ellipses if you have the
plot aspect ratio as something other than 1:1.

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: making a circle of certain values [message #56126 is a reply to message #56123] Tue, 02 October 2007 08:24 Go to previous message
Loren Anderson is currently offline  Loren Anderson
Messages: 22
Registered: August 2007
Junior Member
On Oct 1, 4:21 pm, Jean H <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
wrote:
> rpert...@gmail.com wrote:
>> Hi,
>> I have a set of data points (x,y coordinates) that can be plotted on
>> my 1240,1024 array. However, they are sparse x,y spots across the
>> image, and I want to 'thicken' it by drawing a circle with my x,y as
>> centers. I want to give it a certain radius and a certain value too,
>> so that the pixels in the circle (the filling) have values and can
>> thus contribute to my rgb image...
>> anyone know how to draw a circle, and assign a value to pixels within
>> that circle?
>
>> Thanks!
>> RP
>
> Hi,
>
> I am not sure if you want to display the circle or not. If not, you can
> compute the distances from your pixel to every other pixels, then select
> only the cells that are close enough. Here is a code I wrote a long time
> ago (might not be the most optimized one, but it works well!)
>
> So, you have an image of 100*200:
> distances = distanceInMatrix(image, PointX,PointY, 100)
> circle = where(distances le radius)
> image[circle] = newValue
>
> Jean.
>
> ;This function compute for every point in the array the distance to the
> origine point.
> ;INPUT: indexCells: a 1D or 2D array of coordinate, for which the
> ;distances will be computed.
> ; xPos and yPos: the position of the origine point
> ; x_size: the size of the matrix (number of columns)
> ;OUTPUT: a float array of distances to the origine point
> ;
> ;Author: Jean-Gabriel Hasbani
> ; jghas...@DELETETHIS.ucalgary.ANDTHIS.ca
> ; September 2005
>
> function distanceInMatrix, indexCells, xPos,yPos, x_size
> ;print, "the index", indexCells
> numberOfDistances = N_elements(indexCells)
>
> ;get the X;Y coordinate of the points.
> coordCells = ulonarr(2,numberOfDistances)
> coordCells[1,*] = indexCells[*] / x_size ;Y
> coordCells[0,*] = indexCells[*] - x_size * coordCells[1,*] ;X
>
> distances = fltarr(numberOfDistances)
> distances[*] = sqrt((xPos*1.0 - coordCells[0,*]*1.0)^2+(yPos*1.0-
> coordCells[1,*]*1.0)^2)
>
> ;print, coordCells
> ;print, "In the distance Matrix:", distances
> return, distances
> end


I'm not sure if this is what you need, but here are the guts of the
tvcircle routine that David suggested:

FUNCTION Circle, radius, xcenter, ycenter, NPoints=NPoints
; Returns the x and y values of a circle

IF N_Elements(NPoints) EQ 0 THEN NPoints=100

seeds = Findgen(npoints)/(npoints-1)*2*!pi
xvals = sin(seeds)*radius+xcenter
yvals = cos(seeds)*radius+ycenter

RETURN, Transpose([[xvals], [yvals]])
END


Unlike, tvcircle, this doesn't plot the values, is just returns them
in an array that you can plot yourself. If you need particular pixel
locations instead of floats, just change to longs.

circlevals = round(circle(50, 50, 20))

-Loren
Re: making a circle of certain values [message #56130 is a reply to message #56126] Mon, 01 October 2007 13:21 Go to previous message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
rpertaub@gmail.com wrote:
> Hi,
> I have a set of data points (x,y coordinates) that can be plotted on
> my 1240,1024 array. However, they are sparse x,y spots across the
> image, and I want to 'thicken' it by drawing a circle with my x,y as
> centers. I want to give it a certain radius and a certain value too,
> so that the pixels in the circle (the filling) have values and can
> thus contribute to my rgb image...
> anyone know how to draw a circle, and assign a value to pixels within
> that circle?
>
> Thanks!
> RP
>

Hi,

I am not sure if you want to display the circle or not. If not, you can
compute the distances from your pixel to every other pixels, then select
only the cells that are close enough. Here is a code I wrote a long time
ago (might not be the most optimized one, but it works well!)

So, you have an image of 100*200:
distances = distanceInMatrix(image, PointX,PointY, 100)
circle = where(distances le radius)
image[circle] = newValue

Jean.


;This function compute for every point in the array the distance to the
origine point.
;INPUT: indexCells: a 1D or 2D array of coordinate, for which the
;distances will be computed.
; xPos and yPos: the position of the origine point
; x_size: the size of the matrix (number of columns)
;OUTPUT: a float array of distances to the origine point
;
;Author: Jean-Gabriel Hasbani
; jghasban@DELETETHIS.ucalgary.ANDTHIS.ca
; September 2005

function distanceInMatrix, indexCells, xPos,yPos, x_size
;print, "the index", indexCells
numberOfDistances = N_elements(indexCells)

;get the X;Y coordinate of the points.
coordCells = ulonarr(2,numberOfDistances)
coordCells[1,*] = indexCells[*] / x_size ;Y
coordCells[0,*] = indexCells[*] - x_size * coordCells[1,*] ;X


distances = fltarr(numberOfDistances)
distances[*] = sqrt((xPos*1.0 - coordCells[0,*]*1.0)^2+(yPos*1.0-
coordCells[1,*]*1.0)^2)

;print, coordCells
;print, "In the distance Matrix:", distances
return, distances
end
Re: making a circle of certain values [message #56131 is a reply to message #56130] Mon, 01 October 2007 13:09 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
rpertaub@gmail.com writes:

> I have a set of data points (x,y coordinates) that can be plotted on
> my 1240,1024 array. However, they are sparse x,y spots across the
> image, and I want to 'thicken' it by drawing a circle with my x,y as
> centers. I want to give it a certain radius and a certain value too,
> so that the pixels in the circle (the filling) have values and can
> thus contribute to my rgb image...
> anyone know how to draw a circle, and assign a value to pixels within
> that circle?

I'd use the most useful routine I ever downloaded from the NASA
Astronomy library: TVCIRCLE.

You will probably have to write a new output keyword for that routine
to recover the XY locations of the polygon it creates for the circle.
Then use POLYFILLV to find the indices of the image inside that polygon.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: SetPixelData Error
Next Topic: label x axis

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

Current Time: Sat Oct 11 12:56:09 PDT 2025

Total time taken to generate the page: 0.64622 seconds