Re: how many array elements with a certain value in a row [message #70268] |
Thu, 01 April 2010 08:22 |
jeanh
Messages: 79 Registered: November 2009
|
Member |
|
|
On 01/04/2010 8:49 AM, Jeremy Bailin wrote:
> Does anyone have a nice simple efficient solution to this problem (I
> have a simple inefficient solution and a vague sketch in my mind of a
> convoluted but probably efficient solution):
>
> I have an image in which many pixels are saturated (=65535, they're
> short unsigned). I want to treat each set of consecutive saturated
> pixels in a row as a single unit and know how many saturated pixels in
> a row there are. So I would like to have a list that contains (a) the
> rightmost pixel of each set of consecutive saturated pixels, and (b)
> how many saturated pixels there were in the set.
>
> Any suggestions?
>
> -Jeremy.
Hi,
what about using shift? ... untested and though in a baby-scream
environment, so sorry if I miss the obvious
a) select pixels with the targeted value (where)
b) do img-shift(img)
c) look at the indexes found in a) and that are positive in b) so that
you only get the ending position.
Jean
|
|
|
Re: how many array elements with a certain value in a row [message #70269 is a reply to message #70268] |
Thu, 01 April 2010 08:11  |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
On Apr 1, 10:14 am, Chris W <cwood1...@gmail.com> wrote:
> On Apr 1, 8:56 am, Jeremy Bailin <astroco...@gmail.com> wrote:
>
>
>
>
>
>> On Apr 1, 9:48 am, Chris W <cwood1...@gmail.com> wrote:
>
>>> On Apr 1, 7:49 am, Jeremy Bailin <astroco...@gmail.com> wrote:
>
>>>> Does anyone have a nice simple efficient solution to this problem (I
>>>> have a simple inefficient solution and a vague sketch in my mind of a
>>>> convoluted but probably efficient solution):
>
>>>> I have an image in which many pixels are saturated (=65535, they're
>>>> short unsigned). I want to treat each set of consecutive saturated
>>>> pixels in a row as a single unit and know how many saturated pixels in
>>>> a row there are. So I would like to have a list that contains (a) the
>>>> rightmost pixel of each set of consecutive saturated pixels, and (b)
>>>> how many saturated pixels there were in the set.
>
>>>> Any suggestions?
>
>>>> -Jeremy.
>
>>> create an array the same size as the image, with values equal to the x
>>> index ([0,1,2,3,4,5,.....]:
>
>>> x = indgen(512)
>>> rx = rebin(x,512,512)
>
>>> ;;create a mask
>>> mask = image eq 65535
>
>>> ;; index values of the mask
>>> rxmask = rx*mask
>
>>> rightvalues = max(rxmask, dimension=1)
>
>>> number_in_rows = total(mask, 1)
>
>> No, that won't work - it will only pick up one set per row. There
>> could be none or many sets in a ny given row.
>
>> -Jeremy.
>
> How about using reform to convert the 2d image into a vector, use
> label region to number each set, then histogram with reverse_indices
> to find the coordinates of each set (the number in each set will be
> the histogram values).
>
> Chris
Yeah, that's good - it's basically what Ben was suggesting, but doing
that reform at the beginning takes away a lot of the extra bookkeeping
that was making me avoid it. Just need to throw an extra column of 0s
at the edge of the image before the reform to make sure that a run at
the end of one row doesn't get attached to any at the beginning of the
next row.
Thanks!
-Jeremy.
|
|
|
Re: how many array elements with a certain value in a row [message #70270 is a reply to message #70269] |
Thu, 01 April 2010 07:14  |
Chris W
Messages: 12 Registered: May 2007
|
Junior Member |
|
|
On Apr 1, 8:56 am, Jeremy Bailin <astroco...@gmail.com> wrote:
> On Apr 1, 9:48 am, Chris W <cwood1...@gmail.com> wrote:
>
>
>
>> On Apr 1, 7:49 am, Jeremy Bailin <astroco...@gmail.com> wrote:
>
>>> Does anyone have a nice simple efficient solution to this problem (I
>>> have a simple inefficient solution and a vague sketch in my mind of a
>>> convoluted but probably efficient solution):
>
>>> I have an image in which many pixels are saturated (=65535, they're
>>> short unsigned). I want to treat each set of consecutive saturated
>>> pixels in a row as a single unit and know how many saturated pixels in
>>> a row there are. So I would like to have a list that contains (a) the
>>> rightmost pixel of each set of consecutive saturated pixels, and (b)
>>> how many saturated pixels there were in the set.
>
>>> Any suggestions?
>
>>> -Jeremy.
>
>> create an array the same size as the image, with values equal to the x
>> index ([0,1,2,3,4,5,.....]:
>
>> x = indgen(512)
>> rx = rebin(x,512,512)
>
>> ;;create a mask
>> mask = image eq 65535
>
>> ;; index values of the mask
>> rxmask = rx*mask
>
>> rightvalues = max(rxmask, dimension=1)
>
>> number_in_rows = total(mask, 1)
>
> No, that won't work - it will only pick up one set per row. There
> could be none or many sets in a ny given row.
>
> -Jeremy.
How about using reform to convert the 2d image into a vector, use
label region to number each set, then histogram with reverse_indices
to find the coordinates of each set (the number in each set will be
the histogram values).
Chris
|
|
|
Re: how many array elements with a certain value in a row [message #70271 is a reply to message #70270] |
Thu, 01 April 2010 06:56  |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
On Apr 1, 9:48 am, Chris W <cwood1...@gmail.com> wrote:
> On Apr 1, 7:49 am, Jeremy Bailin <astroco...@gmail.com> wrote:
>
>> Does anyone have a nice simple efficient solution to this problem (I
>> have a simple inefficient solution and a vague sketch in my mind of a
>> convoluted but probably efficient solution):
>
>> I have an image in which many pixels are saturated (=65535, they're
>> short unsigned). I want to treat each set of consecutive saturated
>> pixels in a row as a single unit and know how many saturated pixels in
>> a row there are. So I would like to have a list that contains (a) the
>> rightmost pixel of each set of consecutive saturated pixels, and (b)
>> how many saturated pixels there were in the set.
>
>> Any suggestions?
>
>> -Jeremy.
>
> create an array the same size as the image, with values equal to the x
> index ([0,1,2,3,4,5,.....]:
>
> x = indgen(512)
> rx = rebin(x,512,512)
>
> ;;create a mask
> mask = image eq 65535
>
> ;; index values of the mask
> rxmask = rx*mask
>
> rightvalues = max(rxmask, dimension=1)
>
> number_in_rows = total(mask, 1)
No, that won't work - it will only pick up one set per row. There
could be none or many sets in a ny given row.
-Jeremy.
|
|
|
Re: how many array elements with a certain value in a row [message #70272 is a reply to message #70271] |
Thu, 01 April 2010 06:48  |
Chris W
Messages: 12 Registered: May 2007
|
Junior Member |
|
|
On Apr 1, 7:49 am, Jeremy Bailin <astroco...@gmail.com> wrote:
> Does anyone have a nice simple efficient solution to this problem (I
> have a simple inefficient solution and a vague sketch in my mind of a
> convoluted but probably efficient solution):
>
> I have an image in which many pixels are saturated (=65535, they're
> short unsigned). I want to treat each set of consecutive saturated
> pixels in a row as a single unit and know how many saturated pixels in
> a row there are. So I would like to have a list that contains (a) the
> rightmost pixel of each set of consecutive saturated pixels, and (b)
> how many saturated pixels there were in the set.
>
> Any suggestions?
>
> -Jeremy.
create an array the same size as the image, with values equal to the x
index ([0,1,2,3,4,5,.....]:
x = indgen(512)
rx = rebin(x,512,512)
;;create a mask
mask = image eq 65535
;; index values of the mask
rxmask = rx*mask
rightvalues = max(rxmask, dimension=1)
number_in_rows = total(mask, 1)
|
|
|
Re: how many array elements with a certain value in a row [message #70273 is a reply to message #70272] |
Thu, 01 April 2010 06:40  |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
> That sounds right. I recall HISTOGRAM scans left to right along rows.
> So a histogram of the labeled image coupled with the reverse indices
> and a row look-up function to convert from index to row should provide
> enough info.
Hmmm, yeah that would probably work. I'm not sure it's any less
convoluted than the TOTAL(/CUMULATIVE)-based solution I was thinking
of.
> Is this like a run-length-encoding you're looking for?
I suppose that someone implementing run-length-encoding would need
similar information, but all I care about are the locations where one
particular value occurs so I can look at the properties of the image
relative to those locations.
-Jeremy.
|
|
|
Re: how many array elements with a certain value in a row [message #70275 is a reply to message #70273] |
Thu, 01 April 2010 06:17  |
ben.bighair
Messages: 221 Registered: April 2007
|
Senior Member |
|
|
On Apr 1, 9:02 am, David Fanning <n...@dfanning.com> wrote:
> Jeremy Bailin writes:
>> Does anyone have a nice simple efficient solution to this problem (I
>> have a simple inefficient solution and a vague sketch in my mind of a
>> convoluted but probably efficient solution):
>
>> I have an image in which many pixels are saturated (=65535, they're
>> short unsigned). I want to treat each set of consecutive saturated
>> pixels in a row as a single unit and know how many saturated pixels in
>> a row there are. So I would like to have a list that contains (a) the
>> rightmost pixel of each set of consecutive saturated pixels, and (b)
>> how many saturated pixels there were in the set.
>
> I'm guessing you could probably work something out with
> LABEL_REGION. As for efficiency...
Hi,
That sounds right. I recall HISTOGRAM scans left to right along rows.
So a histogram of the labeled image coupled with the reverse indices
and a row look-up function to convert from index to row should provide
enough info.
Is this like a run-length-encoding you're looking for?
Cheers,Ben
|
|
|
Re: how many array elements with a certain value in a row [message #70277 is a reply to message #70275] |
Thu, 01 April 2010 06:03  |
Gray
Messages: 253 Registered: February 2010
|
Senior Member |
|
|
On Apr 1, 8:49 am, Jeremy Bailin <astroco...@gmail.com> wrote:
> Does anyone have a nice simple efficient solution to this problem (I
> have a simple inefficient solution and a vague sketch in my mind of a
> convoluted but probably efficient solution):
>
> I have an image in which many pixels are saturated (=65535, they're
> short unsigned). I want to treat each set of consecutive saturated
> pixels in a row as a single unit and know how many saturated pixels in
> a row there are. So I would like to have a list that contains (a) the
> rightmost pixel of each set of consecutive saturated pixels, and (b)
> how many saturated pixels there were in the set.
>
> Any suggestions?
>
> -Jeremy.
Well, the weird idea I just had was convert each row to a string, then
run STREGEX to find the saturated values.
|
|
|
Re: how many array elements with a certain value in a row [message #70278 is a reply to message #70277] |
Thu, 01 April 2010 06:02  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Jeremy Bailin writes:
> Does anyone have a nice simple efficient solution to this problem (I
> have a simple inefficient solution and a vague sketch in my mind of a
> convoluted but probably efficient solution):
>
> I have an image in which many pixels are saturated (=65535, they're
> short unsigned). I want to treat each set of consecutive saturated
> pixels in a row as a single unit and know how many saturated pixels in
> a row there are. So I would like to have a list that contains (a) the
> rightmost pixel of each set of consecutive saturated pixels, and (b)
> how many saturated pixels there were in the set.
I'm guessing you could probably work something out with
LABEL_REGION. As for efficiency...
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|