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

Home » Public Forums » archive » filling holes in blobs quickly
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
filling holes in blobs quickly [message #30231] Mon, 15 April 2002 15:17 Go to next message
dmartin is currently offline  dmartin
Messages: 5
Registered: April 2002
Junior Member
I'm sure this is a well solved problem, but:
I'm trying to fill in holes inside of domains (blobs) quickly. The
domains are in a binary image, and are bright.

Right now, I search for dark regions - the holes (label_region);
pick out those of a small size (histogram and where);
and then fill them in (a FOR loop through the where values, since I
don't know how to get where to compare to every value in a vector).

This is slow, and I strongly suspect there is an intelligent way to do
this: fill in all dark blobs up to a certain size.

Thanks for any help,

Doug Martin
University of Texas at Austin
Re: filling holes in blobs quickly [message #30360 is a reply to message #30231] Thu, 18 April 2002 10:07 Go to previous message
Karsten Rodenacker is currently offline  Karsten Rodenacker
Messages: 98
Registered: July 1997
Member
Oups, I forgot function mm_bord. It creats an array of same size with
borders two bits set (with keyword /del) .
;+
;
NAME:
;
MM_BORD
;
function mm_bord,a,n,VALUE=val,Z_FIRST=z_fir, ALL=all, DELETE = del
if n_params() eq 1 then n=1
if not keyword_set(val) then val=0
sx=size(a)
IF NOT keyword_set(del) THEN e=a ELSE e = make_array(size = sx)
case sx(0) of
1:begin
e([0,sx(1)-1])=val
end
2:begin
wx=[indgen(n),sx(1)-indgen(n)-1]
wy=[indgen(n),sx(2)-indgen(n)-1]
e(wx,*)=val & e(*,wy)=val
end
3:begin
if keyword_set(z_fir) then begin
wx=[indgen(n),sx(2)-indgen(n)-1]
wy=[indgen(n),sx(3)-indgen(n)-1]
e(*,wx,*)=val & e(*,*,wy)=val
if keyword_set(all) then begin
e[0:n-1,*,*]=val
e[sx[1]-n:sx[1]-1,*,*]=val
endif
endif else begin
wx=[indgen(n),sx(1)-indgen(n)-1]
wy=[indgen(n),sx(2)-indgen(n)-1]
e(wx,*,*)=val & e(*,wy,*)=val
if keyword_set(all) then begin
e[*,*,0:n-1]=val
e[*,*,sx[3]-n:sx[3]-1]=val
endif
endelse
end
4:begin ; first coordinate not considered
if keyword_set(z_fir) then begin
wx=[indgen(n),sx(3)-indgen(n)-1]
wy=[indgen(n),sx(4)-indgen(n)-1]
e(*,*,wx,*)=val & e(*,*,*,wy)=val
if keyword_set(all) then begin
e[*,0:n-1,*,*]=val
e[*,sx[1]-n:sx[1]-1,*,*]=val
endif
endif else begin
wx=[indgen(n),sx(2)-indgen(n)-1]
wy=[indgen(n),sx(3)-indgen(n)-1]
e(*,wx,*,*)=val & e(*,*,wy,*)=val
if keyword_set(all) then begin
e[*,*,*,0:n-1]=val
e[*,*,*,sx[1]-n:sx[1]-1]=val
endif
endelse
end
else:
endcase
return,e
end
;-


May be this routine does what you like. However, there should be
background touching the image border!
Regards
;+
; NAME:
;
MM_FILL_NEW
;
;
; PURPOSE:
;
Fills holes
;
;
; CATEGORY:
;
Image processing
;
;
; CALLING SEQUENCE:
;
result = MM_FILL_NEW(mask)
;
;
; INPUTS:
;
mask:
An image from which only pixels ne 0 are considered
;
;
; OPTIONAL INPUTS:
;
none
;
;
; KEYWORD PARAMETERS:
;
EIGHT:
Neighborhood used is 8-connected (def. 4)
;
see label_region
;
;
; OUTPUTS:
;
A filled byte mask image
;
;
; OPTIONAL OUTPUTS:
;
none
;
;
; COMMON BLOCKS:
;
none
;
;
; SIDE EFFECTS:
;
label_region is used
;
;
; RESTRICTIONS:
;
;
;
; PROCEDURE:
;
;
;
; EXAMPLE:
;
;
;
; MODIFICATION HISTORY:
;
; Wed Oct 1 09:11:34 1997, Karsten Rodenacker
; <rodena@gsf.de>
;
;
;
;-
FUNCTION MM_FILL_NEW, inp, ALL = all, _EXTRA=ext
b = byte(inp NE 0)
l = label_region(1b-b, _EXTRA=ext)
bg = where(histogram(byte(l*mm_bord(b,2,val=1, /del, all = all))) ne
0, cbg)
hl = uindgen(max(l)+1)
hl[bg] = 0
return, b OR (hl[l] NE 0)
; print,cbg, bg
; IF cbg GT 1 THEN FOR i=1, cbg-1 DO BEGIN
; l[where(l EQ bg[i])] = 0
; tvscl, l
; ENDFOR
; return, b OR byte(l NE 0)
end


Doug Martin wrote:

> I'm sure this is a well solved problem, but:
> I'm trying to fill in holes inside of domains (blobs) quickly. The
> domains are in a binary image, and are bright.
>
> Right now, I search for dark regions - the holes (label_region);
> pick out those of a small size (histogram and where);
> and then fill them in (a FOR loop through the where values, since I
> don't know how to get where to compare to every value in a vector).
>
> This is slow, and I strongly suspect there is an intelligent way to do
> this: fill in all dark blobs up to a certain size.
>
> Thanks for any help,
>
> Doug Martin
> University of Texas at Austin
>


--
Karsten Rodenacker ()
------------------------------------------------------------ -------------:-)
GSF - Forschungszentrum Institute of Biomathematics and Biometry
D-85758 Oberschleissheim Postfach 11 29
Tel: +49 89 31873401 | FAX: ...3369 | rodena@gsf.de |
Karsten@Rodenacker.de
http://www.gsf.de/ibb/homepages/rodenacker
Re: filling holes in blobs quickly [message #30362 is a reply to message #30231] Thu, 18 April 2002 10:02 Go to previous message
Karsten Rodenacker is currently offline  Karsten Rodenacker
Messages: 98
Registered: July 1997
Member
May be this routine does what you like. However, there should be
background touching the image border!
Regards
;+
; NAME:
;
MM_FILL_NEW
;
;
; PURPOSE:
;
Fills holes
;
;
; CATEGORY:
;
Image processing
;
;
; CALLING SEQUENCE:
;
result = MM_FILL_NEW(mask)
;
;
; INPUTS:
;
mask:
An image from which only pixels ne 0 are considered
;
;
; OPTIONAL INPUTS:
;
none
;
;
; KEYWORD PARAMETERS:
;
EIGHT:
Neighborhood used is 8-connected (def. 4)
;
see label_region
;
;
; OUTPUTS:
;
A filled byte mask image
;
;
; OPTIONAL OUTPUTS:
;
none
;
;
; COMMON BLOCKS:
;
none
;
;
; SIDE EFFECTS:
;
label_region is used
;
;
; RESTRICTIONS:
;
;
;
; PROCEDURE:
;
;
;
; EXAMPLE:
;
;
;
; MODIFICATION HISTORY:
;
; Wed Oct 1 09:11:34 1997, Karsten Rodenacker
; <rodena@gsf.de>
;
;
;
;-
FUNCTION MM_FILL_NEW, inp, ALL = all, _EXTRA=ext
b = byte(inp NE 0)
l = label_region(1b-b, _EXTRA=ext)
bg = where(histogram(byte(l*mm_bord(b,2,val=1, /del, all = all))) ne
0, cbg)
hl = uindgen(max(l)+1)
hl[bg] = 0
return, b OR (hl[l] NE 0)
; print,cbg, bg
; IF cbg GT 1 THEN FOR i=1, cbg-1 DO BEGIN
; l[where(l EQ bg[i])] = 0
; tvscl, l
; ENDFOR
; return, b OR byte(l NE 0)
end


Doug Martin wrote:

> I'm sure this is a well solved problem, but:
> I'm trying to fill in holes inside of domains (blobs) quickly. The
> domains are in a binary image, and are bright.
>
> Right now, I search for dark regions - the holes (label_region);
> pick out those of a small size (histogram and where);
> and then fill them in (a FOR loop through the where values, since I
> don't know how to get where to compare to every value in a vector).
>
> This is slow, and I strongly suspect there is an intelligent way to do
> this: fill in all dark blobs up to a certain size.
>
> Thanks for any help,
>
> Doug Martin
> University of Texas at Austin
>


--
Karsten Rodenacker ()
------------------------------------------------------------ -------------:-)
GSF - Forschungszentrum Institute of Biomathematics and Biometry
D-85758 Oberschleissheim Postfach 11 29
Tel: +49 89 31873401 | FAX: ...3369 | rodena@gsf.de |
Karsten@Rodenacker.de
http://www.gsf.de/ibb/homepages/rodenacker
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: off-white background in IDL-generated bitmaps
Next Topic: Re: cw_defroi vertices.

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

Current Time: Wed Oct 08 16:56:42 PDT 2025

Total time taken to generate the page: 0.00572 seconds