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

Home » Public Forums » archive » Re: segmentation / thresholding
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: segmentation / thresholding [message #9783] Sun, 24 August 1997 00:00
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
scd@gopher.chem.wayne.edu writes:

> I am a new user of IDL and of this newsgroup.
> Is it possible to threshold / segment images with IDL ? Especially, is
> there any histogram-based methods that will partition automatically my
> arrays ?

It is easily possible to threshold/segment images in IDL.
Consider the world elevation data set that comes with IDL.

file = Filepath(Subdirectory=['examples','data'], 'worldelv.dat')
image = BytArr(360,360)
OpenR, lun, file, /Get_Lun
ReadU, lun, image
Free_Lun, lun
Window, XSize=360, YSize=360

Suppose you just want to view the pixels between 50
and 150 in this image. You would type:

TV, 50 > image < 150

Sometimes when you threshold an image you want a black and
white image. You might use the WHERE function in IDL
to do this, like this:

b_w = image*0
b_w(Where(image LT 150 AND image GT 50)) = 255
TV, b_w

You can use the IDL example program XStretch that is on my
web page to apply an interactive stretch or thresholding
to an image. XStretch allows you to view the image histogram
while moving two bars. The pixel values between the two
bars are "stretched" over the available colors.

If you want to do image segmentation, the WHERE function
is invaluable. For example, suppose you want to make the
pixels between 75 and 100 red. You can type this:

segImage = BytScl(image, Top=!D.N_Colors-2)
TVLCT, 255, 0, 0, !D.N_Colors-1
segImage(Where(image GT 75 AND image LT 100))=!D.N_Colors-1
TV, segImage

> Also, if anybody knows how SEARCH2D works... and can provide me with
> an example.

You can see how Search2D works yourself. The IDL code for
Search2D is located in the lib subdirectory of the main IDL
directory. It basically uses the WHERE function to search
for pixels near a specific pixel that has a value within
some defined threshold value. To search for a region about the
point (134, 134), with values of plus or minus 10, you can do this.

segImage = BytScl(image, Top=!D.N_Colors-2)
TVLCT, 255, 0, 0, !D.N_Colors-1
region = Search2D(segImage, 134, 134, segImage(134,134)-10, $
segImage(134,134)+10)
segImage(region) = !D.N_Colors-1
TV, segImage

Hope this gives you some ideas.

Cheers,

David

------------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
Customizable IDL Programming Courses
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com
[Message index]
 
Read Message
Previous Topic: 2D or 1D
Next Topic: Re: labels on log Axes

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

Current Time: Sat Oct 11 12:31:03 PDT 2025

Total time taken to generate the page: 2.39917 seconds