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 
Return to the default flat view Create a new topic Submit Reply
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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
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: Fri Oct 10 18:17:40 PDT 2025

Total time taken to generate the page: 2.46485 seconds