Re: Objects in ENVI ROI files [message #90506 is a reply to message #84526] |
Thu, 05 March 2015 10:02   |
samsammurphy
Messages: 2 Registered: March 2015
|
Junior Member |
|
|
On Tuesday, May 21, 2013 at 2:08:47 AM UTC-3, Josh Sixsmith wrote:
> Considering that the original post was back in 2006, it has probably already been solved.
>
> Anyway, here is one method that should achieve what you're after.
>
> Rather than use region_grow to find all of the values. Use a dummy array of the same x/y dimensions as to what the ROI is based off, and label it. This will be similar (if not the same as) to the region grow method, without the iterations.
>
> You can use the roi addresses to index the dummy array and set the value to one (all other pixels should be zero).
> Then use label_region. This will give each of your roi polygons a unique identifier.
> The next step would be to find all the unique labels, using a combination of uniq and sort.
> Use the histogram function and reverse indices. This can then be used to index the original array and do whatever you want, such as assign a new value, or calculate some stats.
>
> The bins of interest are defined by the unique labels, which are also sorted. We know that the background is zero so ignore it when looping over the bins.
>
> Eg:
> dummy = bytarr(samples,lines)
> dummy[roi_addr] = 1
> label_arr = label_region(dummy)
> labels = label_arr[uniq(label_arr, sort(label_arr))]
> hist = histogram(label_arr, min=0, max=max(labels), reverse_indices=ri)
>
> for i=1,n_elements(labels)-1 do begin
> if hist[labels[i]] eq 0 then continue
> ;retrieve the data from the original array
> polygon = orig_data[ri[ri[labels[i]]:ri[labels[i]+1]-1]]
> ;do something
> endfor
>
> That should get the individual polygons within each ROI that you're after.
>
> Cheers
> Josh
Thanks for posting this. It is what I was looking for - looks like its a subject that comes around every few years :)
|
|
|