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

Home » Public Forums » archive » Re: Fill in a logic image: possible in IDL ?
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: Fill in a logic image: possible in IDL ? [message #24708] Mon, 16 April 2001 09:41
Ivan Zimine is currently offline  Ivan Zimine
Messages: 40
Registered: February 1999
Member
jsilva@ci.uc.pt wrote:
>
> Hello
> To explain what I?m trying to do about a FILL in a logic image, I give an
> example (see the Computer Tomography lung image in
> http://www.ci.uc.pt/pessoal/jsilva/idl_fill.jpg )
> Thanks in advance for any suggestion.
> Jose Silva
> Physics Dep., FCTUC, Portugal
>

mask = byte(median(image gt 50, 9))
roi = search2d(mask, 0, 510, 0, 0)
msk1 = mask*0b
msk1[roi] = 1
roi = search2d(mask, 27, 32, 0, 0)
msk2 = mask*0b
msk2[roi] = 1

back_mask = msk1 or msk2
image_mask = 1 - back_mask


--
Ivan Zimine | ivan.zimine@physics.unige.ch
Dpt. of Radiology | (+41 22) 372 70 70
Geneva University Hospitals |
Re: Fill in a logic image: possible in IDL ? [message #24712 is a reply to message #24708] Sun, 15 April 2001 12:10 Go to previous message
John-David T. Smith is currently offline  John-David T. Smith
Messages: 384
Registered: January 2000
Senior Member
jsilva@ci.uc.pt wrote:
>
> Hello
> To explain what I?m trying to do about a FILL in a logic image, I give an
> example (see the Computer Tomography lung image in
> http://www.ci.uc.pt/pessoal/jsilva/idl_fill.jpg )
> Thanks in advance for any suggestion.
> Jose Silva
> Physics Dep., FCTUC, Portugal

OK, I think I see now... you want to do blob coloring, aka "fill" from
your favorite paint program. The IDL function label_region works well
for this. It's quite simple. The JHU library contains two example
programs for this, but I'll summarize:

labels=label_region(image LE level)
image[where(labels eq labels[x,y])]=fill

OK, so what does this do? label_region finds continuous blobs of
non-zero values, and gives them a non-zero "ID". You find the ID of
seed pixel (x,y), and where that blob exists in the array, then setting
this region to whatever fill value you like.

Note that all edge pixels are considered to be in no region
(label_region returns zero there). This seems dumb to me... one
workaround is to fill dummy rows and columns on the exterior with 1's.
You should probably also test that the region exists, or else you'll end
up filling all the pixels in no region. e.g.

if labels[x,y] ne 0 then ...

Another JHU program illustrates the flexibility of this method... since
you can make masks in many ways, you can label all sorts of interesting
things like boundary regions... the inverse of the former problem:

labels=label_region(image ne boundary)

or even

labels=label_region(image gt bmax OR image lt bmin)

Here we label all areas bordered by boundary values in some range.

Search2D can do this too, but I think label_region gives more
flexibility. Since it just finds regions of non-zero value in a mask,
you can conceive of doing all sorts of cool things. Here are a few
interesting challenges:

1. Region of strictly decreasing value from a seed pixel. Or try
increasing.

2. Region contiguous to seed pixel which is within 10% of the full data
range to it.

3. Region contiguous to seed pixel with values in the nearest Nth
percentile (think histogram).

4. Region contiguous to seed pixel which alternate even to odd.

etc.

Good luck,

JD
Re: Fill in a logic image: possible in IDL ? [message #24713 is a reply to message #24712] Sun, 15 April 2001 07:58 Go to previous message
jsilva is currently offline  jsilva
Messages: 1
Registered: April 2001
Junior Member
Hello
To explain what I�m trying to do about a FILL in a logic image, I give an
example (see the Computer Tomography lung image in
http://www.ci.uc.pt/pessoal/jsilva/idl_fill.jpg )
Thanks in advance for any suggestion.
Jose Silva
Physics Dep., FCTUC, Portugal




In article <3AD969AE.1A198238@physics.unige.ch>, Ivan Zimine says...
>
> Jose Silva wrote:
>>
>> Hello
>> I have a grayscale image (512 x 512 x 1 byte from medical TAC).
>> I applied a threshold to have a logic mask and tried to do a fill in that
>> mask
>> in order to remove some background. Most of languages have a fill command,
>> like FILL in draw programs that FILLs the image starting in X,Y (user
>> defined)
>> coordenations.
>> I search throw IDL commands and I never found any FILL command (or identical
>> command).
>> As most of languages (eg MATLAB and many others) have a FILL (BWFILL in
>> MATLAB, as morphologic operation), did I miss the FILL in IDL or there isn?t
>> any FILL in IDL?
>
> IDL> ?search2d
Re: Fill in a logic image: possible in IDL ? [message #24715 is a reply to message #24713] Sun, 15 April 2001 02:28 Go to previous message
Ivan Zimine is currently offline  Ivan Zimine
Messages: 40
Registered: February 1999
Member
Jose Silva wrote:
>
> Hello
> I have a grayscale image (512 x 512 x 1 byte from medical TAC).
> I applied a threshold to have a logic mask and tried to do a fill in that
> mask
> in order to remove some background. Most of languages have a fill command,
> like FILL in draw programs that FILLs the image starting in X,Y (user
> defined)
> coordenations.
> I search throw IDL commands and I never found any FILL command (or identical
> command).
> As most of languages (eg MATLAB and many others) have a FILL (BWFILL in
> MATLAB, as morphologic operation), did I miss the FILL in IDL or there isn?t
> any FILL in IDL?

IDL> ?search2d


--
Ivan Zimine | ivan.zimine@physics.unige.ch
Dpt. of Radiology | (+41 22) 372 70 70
Geneva University Hospitals |
Re: Fill in a logic image: possible in IDL ? [message #24716 is a reply to message #24715] Sat, 14 April 2001 19:27 Go to previous message
John-David T. Smith is currently offline  John-David T. Smith
Messages: 384
Registered: January 2000
Senior Member
jsilva@ci.uc.pt wrote:
>
> Hello
> I have a grayscale image (512 x 512 x 1 byte from medical TAC).
> I applied a threshold to have a logic mask and tried to do a fill in that mask
> in order to remove some background. Most of languages have a fill command, like
> FILL in draw programs that FILLs the image starting in X,Y (user defined)
> coordenations.
> I search throw IDL commands and I never found any FILL command (or identical
> command).
> As most of languages (eg MATLAB and many others) have a FILL (BWFILL in MATLAB,
> as morphologic operation), did I miss the FILL in IDL or there isn?t any FILL in
> IDL?
> I tried to use POLYFILL but my mask is very irregular, not being possible to
> apply a POLYFILL in a predefined region.
> Any commend on this subject is welcome?
>
> level=100
> mask= (image LE level) ; TAC of lungs (from TAC) with many irregularities
> ; FILL to ?fill? mask starting (eg) in 1,1 pixel coordination
>
> jsilva @ ci.uc.pt


Unless I've misunderstood, it's probably easier than you think:

mask=where(image LE level,cnt)
if cnt gt 0 then image[mask]=background

or, if you know for sure there are some elements in the mask, you can
just do:

image[where(image LE level)]=background

Notice that here mask is just a list of indices. You can use multiple
masks in one of two (or more) ways, e.g.:

1. immask=image LE level AND image GE otherlevel AND otherim eq 1
mask=where(immask ne 0)
2. mask=where(image LE level)
mask=mask[where(image[mask] GE otherlevel)]
mask=mask[where(otherim[mask] eq 1)]


In case 1, you compute all the comparisons on all the elements of image,
and AND them all together. In case 2, you examine only those elements
which survived the previous test, paring down mask at each step. Both
forms have their advantages. But getting used to lists of indices as
masks or collections of pixels in IDL is vital.

Good luck,

JD

P.S. Here's one other method which doesn't use subscripts, more in line
with your original idea:

mask=image LE level
image=image*(mask)+background*(mask eq 0)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Fill in a logic image: possible in IDL ?
Next Topic: How to read two-bytes variables from a file saved in Mac?

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

Current Time: Wed Oct 08 16:49:20 PDT 2025

Total time taken to generate the page: 0.00695 seconds