Re: How to eliminate smaller blob from label_region image [message #77333] |
Tue, 23 August 2011 05:02  |
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   |
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 #77346 is a reply to message #77335] |
Mon, 22 August 2011 05:37   |
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   |
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  |
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
|
|
|