On 7/12/05 10:51 pm, "Michael von Aichberger 2" <[EMAIL PROTECTED]> wrote:
> maybe some of you know what equidensities are: these are zones of equal or > similar tonal values in a black and white negative. At the time one used > lith film masks to get them. > > I need to do something like that with an alphaChannel image using imaging > lingo, but I am not sure how to do it. > > For me it would be good enough to separate a grayscale image in two images, > one with all tonal values above a given threshold value blackened and > another where all values below this value are black. > > So one could break it down to the question: How do I blacken all areas below > or above a threshold value in a grayscale image? Hi Michael, Do these handlers do what you want? The first blackens all areas brighter than a given threshold value, and the second inverses images. By using them together, you can blacken all areas darker than a given threshold. If you want to get a mask for all images between two threshold values, then you need to 1. Create an image for the lower threshold 2. Create an image for the higher threshold 3. CopyPixels image 2 onto image 1 using [#ink: #reverse] Cheers, James --========================================================================-- on GetTonalThreshold(anImage, aThreshold) ---------------------------- -- INPUT: <anImage> should be an image object or a reference to -- a member with an image property -- <aThreshold> should be an integer between 0 and 255. If -- the input is not valid, 128 will be used by default. -- ACTION: Creates a black and white image where all pixels whose -- grayscale value is aThreshold or less are white, and -- where all other pixels are black. (Dark areas will -- appear white and light areas will appear black). Use -- NegativeImage() to reverse this, if necessary. -- OUTPUT: Returns a 1-bit image with the same dimensions as the -- original -- CAVEAT: Values of aThreshold above 247 will give a completely -- black image. A value of 0 should give a completely -- white image. -------------------------------------------------------------------- -- Error checking anImage = ConvertToImage(anImage) if not anImage then return #imageExpected end if if integerP(aThreshold) then if aThreshold < 0 or aThreshold > 255 then aThreshold = 128 end if else aThreshold = 128 end if -- End of error checking vRect = anImage.rect vWidth = vRect.width vHeight = vRect.height -- Create the output black and white image, and fill it with black. -- Copying a black pixel is faster than using fill on low bitDepth -- images. vBlackAndWhite = image(vWidth, vHeight, 1) vPixel = image(1, 1, 8, #grayscale) -- we'll re-use this with gray vPixel.setPixel(0, 0, rgb(0, 0, 0)) vBlackAndWhite.copyPixels(vPixel, vRect, rect(0, 0, 1, 1)) -- Create a grayscale copy of the original image. Use a high- -- quality (slow) dither to prevent banding. vGrayScale = image(vWidth, vHeight, 8, #grayscale) vGrayScale.copyPixels(anImage, vRect, vRect, [#dither: 1216]) -- Make our pixel the darkest shade that is to be converted to black vPixel.setPixel(0, 0, rgb(aThreshold, aThreshold, aThreshold)) -- Brighten the entire image by this amount. All light pixels will -- become white; these are the ones that will be converted to black. vOptions = [#ink: #addPin] vGrayScale.copyPixels(vPixel, vRect, rect(0, 0, 1, 1), vOptions) -- Copy all the non-white pixels to the black and white image, -- making them white in the process. The white pixels will not be -- copied, so that area will remain black vOptions[#ink] = #backgroundTransparent vOptions[#color] = rgb(255, 255, 255) -- target color in copy vOptions[#bgColor] = rgb(255, 255, 255) -- color ignored in source vBlackAndWhite.copyPixels(vGrayScale, vRect, vRect, vOptions) return vBlackAndWhite end GetTonalThreshold on NegativeImage(anImage) -------------------------------------------- -- INPUT: <anImage> should be an image object or a reference to -- a member with an image property -- <aThreshold> should be an integer between 0 and 255. If -- the input is not valid, 128 will be used by default. -- OUTPUT: Returns an image an image of the same size and bitDepth -- as anImage, where all the pixels are inverted, or an -- error symbol -------------------------------------------------------------------- -- Error checking anImage = ConvertToImage(anImage) if not anImage then return #imageExpected end if -- End of error checking -- Create the output and fill it with black. vRect = anImage.rect vNegative = image(vRect.width, vRect.height, anImage.depth) vNegative.fill(vRect, rgb(0, 0, 0)) vNegative.copyPixels(anImage, vRect, vRect, [#ink: #reverse]) return vNegative end NegativeImage on ConvertToImage(anImage) ------------------------------------------- -- INPUT: <anImage> can be any Lingo value -- OUTPUT: Returns an image object if <anImage> is an image, a -- member with an image property or the name or number of -- such a member. In all other cases, returns VOID. -------------------------------------------------------------------- case ilk(anImage) of #image: return anImage #member: case anImage.type of #bitmap,#Flash,#RealMedia,#shockwave3D,#text, #vectorShape: return anImage.image otherwise return VOID end case #integer, #string: return ConvertToImage(member(anImage)) otherwise: return VOID end case end ConvertToImage [To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email lingo-l@penworks.com (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]