Re: Photoshop selection / pixel colors
Re: Photoshop selection / pixel colors
- Subject: Re: Photoshop selection / pixel colors
- From: "Fleisher, Ken" <email@hidden>
- Date: Wed, 20 Dec 2006 15:47:43 -0500
- Thread-topic: Photoshop selection / pixel colors
Title: Re: Photoshop selection / pixel colors
Thanks! I will have a go at this soon. For some reason, I thought that you could only get one value at a time. I suppose it was because of the way the example I found was written. In any case, thanks again. I’m sure I can make this work now. :-)
Ken
On 12/20/06 3:44 PM, "Stan Cleveland" <email@hidden> wrote:
On 12/20/06 11:58 AM, Fleisher, Ken wrote:
Maybe you have a good suggestion for what I am trying to actually do. I need to get the average pixel color for every pixel in a selection. The same information that is in the histogram palette expanded view when you view one channel at a time.
>From the archives, I found how to get a pixel color by sampling one pixel and going through values 1-256 to see if it’s histogram is “1” and if it is, accept that index as the value. This is crazy! Is there a better way to get an RGB triplet for a single pixel. How about for a group of pixels?
A histogram tells how many pixels there are for each of 256 color values. When there’s just one pixel, only one value will contain a 1, which is the value of that pixel. All the other values hold 0, because there are no pixels with those values.
When there’s a group of pixels, again, you’ll see counts for how many pixels have color value 0, how many have color value 1, etc. like this:
{0, 0, 0, 0, 5, 66, ...} = 0 pixels of color values 0, 1, 2, and 3; 5 pixels of color value 4, 66 pixels of color value 5, etc.
The code below determines a color value average, I believe.
-- randomly generate a pseudo histogram
set histo to {}
repeat with i from 1 to 256
set end of histo to round ((random number) * 50)
end repeat
-- calculate average color value
set numPixels to 0
set totalValue to 0
repeat with i from 1 to 256
set x to contents of item i of histo
set numPixels to numPixels + x
set totalValue to totalValue + (x * i)
end repeat
set avgColorValue to totalValue / numPixels
My code is quick and dirty and might be faulty—I leave it to you to determine whether it does what you need. You can make it faster using one the well-known list speedups (as a reference or script object).
Stan C.
--
Ken Fleisher
Photographer
Imaging & Visual Services
National Gallery of Art
Washington, D.C.
Phone: (202) 712-7471
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users
This email sent to email@hidden