I have the following function to identify blobs in an image, and remove them if they are under a certain size.
With the for-loop the removal is of course very slow, if there are a lot of blobs, now my question is, is it possible to replace the for-loop?
function clean_regions, input, max_size
output = input
tmp = size(input)
input_labels = LABEL_REGION(input, /ULONG)
hist = histogram(input_labels, binsize=1, locations=loc, /nan, /l64)
to_remove = loc(where(hist le max_size))
result_map = MAKE_ARRAY(tmp[1:2], /ULONG, VALUE=0)
to_keep = mg_complement(to_remove, n_elements(loc))
for i=0,n_elements(to_keep)-1 do begin
result_map[where(input_labels EQ to_keep[i])] = 1
endfor
output *= result_map
output = boolean(output gt 0)
return, output
END