Re: Similarity between integers in a list
Re: Similarity between integers in a list
- Subject: Re: Similarity between integers in a list
- From: Martin Orpen <email@hidden>
- Date: Wed, 19 May 2004 10:38:47 +0100
on 19/5/04 7:25 am, BJ Terry at email@hidden wrote:
>
Sorry, didn't realize at first that the abs operator is from satimage's
>
osax. You could use a handler like this to replace it:
>
on abs(val)
>
if (val < 0)
>
return -val
>
else
>
return val
>
end
>
end
Guess I must have it installed :-)
Thought I'd post this bit of the script as it seems to be working fine.
If you ever have the need to sort black and white from colour RGB images,
this should do the trick:
property imageThreshold : 10
tell application "Adobe Photoshop 7.0"
set myDoc to current document
set {x, y} to {width, height} of myDoc
set myVals to {}
repeat 3 times
--limit pixel sampling to central area of image
set myX to random number from (x / 3) to ((x / 3) * 2)
set myY to random number from (y / 3) to ((y / 3) * 2)
tell current document
select region {{myX, myY}, {myX, myY + 1}, {myX + 1, myY + 1},
{myX + 1, myY}} without antialiasing
set {r, g, B} to histogram of channels 1 thru 3
repeat with i from 1 to 256
if item i of r = 1 then
set theRed to round ((256 - i) / 2.56)
end if
if item i of g = 1 then
set theGreen to round ((256 - i) / 2.56)
end if
if item i of B = 1 then
set theBlue to round ((256 - i) / 2.56)
end if
end repeat
set the end of myVals to {theRed, theGreen, theBlue}
end tell
end repeat
end tell
set pixelList to a reference to myVals
set imageType to my neutralp(pixelList)
--handler provided by BJ Terry
on neutralp(pixelList)
set totalDiff to 0
repeat with x from 1 to count pixelList
set currentPixel to item x of pixelList
set diff to abs ((item 1 of currentPixel) - (item 2 of
currentPixel))
set diff to diff + (abs ((item 1 of currentPixel) - (item 3 of
currentPixel)))
set diff to diff + (abs ((item 2 of currentPixel) - (item 3 of
currentPixel)))
set totalDiff to totalDiff + diff
end repeat
return (totalDiff / (count pixelList)) < imageThreshold
end neutralp
Regards
--
Martin Orpen
Idea Digital Imaging Ltd -- The Image Specialists
http://www.idea-digital.com
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.