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

Home » Public Forums » archive » Re: How to eliminate smaller blob from label_region image
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: How to eliminate smaller blob from label_region image [message #77333] Tue, 23 August 2011 05:02 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
vijay s writes:

> thanks for the help and that works fine, now i have the required
> blob (only 2 blob, both are separated and adjacent to each other).
> Now i want to merge both and make as a single blob and want to find
> the new center.

This is typically done with DILATE, if the two blobs are
close enough to each other. There is a pretty good section
on using these morphological operators (including how to
eliminate small blobs) in my last book, if you are
interested. It's on sale through the end of the month. :-)

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: How to eliminate smaller blob from label_region image [message #77334 is a reply to message #77333] Tue, 23 August 2011 04:18 Go to previous messageGo to next message
Wout De Nolf is currently offline  Wout De Nolf
Messages: 194
Registered: October 2008
Senior Member
On Mon, 22 Aug 2011 23:30:15 -0700 (PDT), vijay s
<vijayans.in@gmail.com> wrote:

>
> hi,
>
> thanks for the help and that works fine, now i have the required
> blob (only 2 blob, both are separated and adjacent to each other).
> Now i want to merge both and make as a single blob and want to find
> the new center.
>
> thanks


What do you mean by "new center"? I suppose the center of mass of the
combination of the two blobs? If you know you must have two blobs, you
don't need to remove the small blobs. Just get the blob index of the
two largest blobs and calculate the center of mass of the combined
blob.


; Get image
path=FILEPATH('pollens.jpg',SUBDIR=['examples','demo','demod ata'])
READ_JPEG, path, image

; Get blob indices
b = LABEL_REGION(image gt 160)

; Get population and members of each blob
h = HISTOGRAM(b, REVERSE_INDICES=r)

; Blob indices of the two largest blobs
h[0]=0 ; background
ind=(reverse(sort(h)))[0:1] ; two largest
ind=b[r[r[ind]]] ; get blob indices

; Get the center of mass of the combined blob
b=b eq ind[0] or b eq ind[1]
totalMass = Total(b)
s=size(b,/dim)
xcm = Total( Total(b, 2) * lindgen(s[0]) ) / totalMass
ycm = Total( Total(b, 1) * lindgen(s[1]) ) / totalMass

; Show result
loadct,3
tvscl,b
tmp=indgen(11)-5
plots,xcm,ycm+tmp,/device,color=150
plots,xcm+tmp,ycm,/device,color=150
print,'Center of mass: ',xcm,ycm
Re: How to eliminate smaller blob from label_region image [message #77335 is a reply to message #77334] Mon, 22 August 2011 23:30 Go to previous messageGo to next message
vijay s is currently offline  vijay s
Messages: 4
Registered: August 2011
Junior Member
hi,

thanks for the help and that works fine, now i have the required
blob (only 2 blob, both are separated and adjacent to each other).
Now i want to merge both and make as a single blob and want to find
the new center.

thanks
Re: How to eliminate smaller blob from label_region image [message #77346 is a reply to message #77335] Mon, 22 August 2011 05:37 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Wox writes:

>
> On Sun, 21 Aug 2011 22:40:24 -0700 (PDT), vijay s
> <vijayans.in@gmail.com> wrote:
>
>> hi all,
>>
>> I used label_region to get individual blob id for each region.
>> But few of my blobs are very small in area wise and
>> i want to eliminate those from my images and retain blobs of larger
>> area (say pixel area gt 10). How can i eliminate unwanted smaller
>> blobs?
>>
>>
>> thanks in advance.
>
>
> By using the HISTOGRAM function:
>
>
> ; Minimum number of blob pixels
> npix_threshold=10
>
> ; Get image
> path=FILEPATH('pollens.jpg',SUBDIR=['examples','demo','demod ata'])
> READ_JPEG, path, image
>
> ; Get blob indices
> b = LABEL_REGION(image gt 150)
>
> ; Get population and members of each blob
> h = HISTOGRAM(b, REVERSE_INDICES=r)
>
> ; Regions with small number of pixels
> ind = where(h lt npix_threshold,ct)
>
> ; Remove the small regions
> for i=0l,ct-1 do b[r[r[ind[i]]:r[ind[i]+1]-1]]=0
>
>
> Obviously, some indices will be missing since you zero'ed them out.
> You might want to fix that. It might not even be necessary to set the
> small blob indices to zero. It all depends on what you will do with
> the blob indices.

This is the method used by the Blob_Analyzer, and it makes
it trivial to deal with blobs below a specific size.

theBlobs = Obj_New('Blob_Analyzer', biLevelImage)
nBlobs = theBlobs -> NumberOfBlobs()
FOR j=0,nBlobs-1 DO BEGIN
indices = theBlobs -> GetIndices(j, COUNT=count)
IF count LE 10 THEN Continue

.... ; Else, do your thing.

ENDFOR

You can find information on the Blob_Analyzer here:

http://www.idlcoyote.com/ip_tips/blobanalysis.html

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: How to eliminate smaller blob from label_region image [message #77347 is a reply to message #77346] Mon, 22 August 2011 01:13 Go to previous messageGo to next message
Wout De Nolf is currently offline  Wout De Nolf
Messages: 194
Registered: October 2008
Senior Member
On Sun, 21 Aug 2011 22:40:24 -0700 (PDT), vijay s
<vijayans.in@gmail.com> wrote:

> hi all,
>
> I used label_region to get individual blob id for each region.
> But few of my blobs are very small in area wise and
> i want to eliminate those from my images and retain blobs of larger
> area (say pixel area gt 10). How can i eliminate unwanted smaller
> blobs?
>
>
> thanks in advance.


By using the HISTOGRAM function:


; Minimum number of blob pixels
npix_threshold=10

; Get image
path=FILEPATH('pollens.jpg',SUBDIR=['examples','demo','demod ata'])
READ_JPEG, path, image

; Get blob indices
b = LABEL_REGION(image gt 150)

; Get population and members of each blob
h = HISTOGRAM(b, REVERSE_INDICES=r)

; Regions with small number of pixels
ind = where(h lt npix_threshold,ct)

; Remove the small regions
for i=0l,ct-1 do b[r[r[ind[i]]:r[ind[i]+1]-1]]=0


Obviously, some indices will be missing since you zero'ed them out.
You might want to fix that. It might not even be necessary to set the
small blob indices to zero. It all depends on what you will do with
the blob indices.
Re: How to eliminate smaller blob from label_region image [message #77423 is a reply to message #77347] Wed, 31 August 2011 05:00 Go to previous message
rogass is currently offline  rogass
Messages: 200
Registered: April 2008
Senior Member
On 22 Aug., 10:13, Wox <s...@nomail.com> wrote:
> On Sun, 21 Aug 2011 22:40:24 -0700 (PDT), vijay s
>
> <vijayans...@gmail.com> wrote:
>> hi all,
>
>>       I used label_region to get individual blob id for each region.
>> But few of my blobs are very small in area wise and
>> i want to eliminate those from my images and retain blobs of larger
>> area (say pixel area gt 10). How can i eliminate unwanted smaller
>> blobs?
>
>> thanks in advance.
>
> By using the HISTOGRAM function:
>
> ; Minimum number of blob pixels
> npix_threshold=10
>
> ; Get image
> path=FILEPATH('pollens.jpg',SUBDIR=['examples','demo','demod ata'])
> READ_JPEG, path, image
>
> ; Get blob indices
> b = LABEL_REGION(image gt 150)
>
> ; Get population and members of each blob
> h = HISTOGRAM(b, REVERSE_INDICES=r)
>
> ; Regions with small number of pixels
> ind = where(h lt npix_threshold,ct)
>
> ; Remove the small regions
> for i=0l,ct-1 do b[r[r[ind[i]]:r[ind[i]+1]-1]]=0
>
> Obviously, some indices will be missing since you zero'ed them out.
> You might want to fix that. It might not even be necessary to set the
> small blob indices to zero. It all depends on what you will do with
> the blob indices.

Yep, and to put all things together:

function cr_remove_regions_fast,mask,small=small,verbose=verbose
small = ~n_elements(small)? 10 : 1>small
verbose = ~n_elements(verbose)? 0 : 1
t0 = systime(1)
l = label_region(mask,/ulong,/all_neighbors)
h = histogram(temporary(l),reverse_indices=r)
wh = where(h,nl)
for i=1l,nl-1l do $
mask[((ind=R[R[wh[I]] : R[wh[i]+1]-1]))] *= $
total( mask[ind]) lt small? 0 : 1
undefine,r,ind,wh; D. Fannings nice undefine routine
if verbose then print,'Filtered regions: ',nl-1l,' in: ',systime(1)-
t0,' s'
return,mask

Cheers

CR
end
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: ackermann number
Next Topic: Finding a large number of files - ls vs file_search?

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

Current Time: Wed Oct 08 15:12:19 PDT 2025

Total time taken to generate the page: 0.00665 seconds