Page 1 of 1
How Do I convert an Image to black and white?
Posted: Sat Aug 30, 2014 2:53 pm
by Fasasoftware
Dear friends,
i need a very little script to transform an image in color to black and white...by pushing a button...
i have tryed some script in livecode's site...but it's don't work.... i saw the grayscale script example that works fine.... but i need only to convert an image to black and white....
can you help me please???
I thank you so much in advance.....
Best regards,
Lestroso

Re: How Do I convert an Image to black and white?
Posted: Sat Aug 30, 2014 3:22 pm
by Klaus
Could you please post the script you already found?
I am sure we can tune it to fit your needs!
Basically, you check if the GRAY value of a pixel is greater or smaller than an certain value (the threshold!)
and then turn that pixel white or black accordingly.

Re: How Do I convert an Image to black and white?
Posted: Sat Aug 30, 2014 4:22 pm
by Fasasoftware
Dear Klaus i found these links but only in livecode's site.....
http://lessons.runrev.com/m/4071/l/2537 ... -grayscale this works very fine!!!
http://runrev.screenstepslive.com/s/352 ... processing <------this script don't work.....
as i told you i need to push a button and convert it from a color image into real black and white image...
Thanks a lot again,
Best regards,
Lestroso

Re: How Do I convert an Image to black and white?
Posted: Sat Aug 30, 2014 4:46 pm
by Klaus
Yes, I knwo what you are looking for!
OK, although this binary stuff is way over my head, I was able to modify the color -> greyscale script according to the logic in my first response
Code: Select all
on mouseUp
# Experiment with this valaue, which decides how grey a pixel must be to trun black or white
put 128 into tThreshold
## 128 = 50% grey!
local tPixel, tImgPosition, tGray, tImage
put the imageData of image "Image" into tImage
# repeat for all the pixels in the image
repeat with tPixel = 0 to (height of image "Image" * width of image "Image") - 1
put tPixel * 4 into tImgPosition
# calculate the gray level - we are using typical weights here
put 0.30 * charToNum (char (tImgPosition + 2) of tImage) + \
0.59 * charToNum (char (tImgPosition + 3) of tImage) + \
0.11 * charToNum (char (tImgPosition + 4) of tImage) into tGray
# set the RGB of the pixel to the same value this gives us the gray level
## Her we decide if the resulting pixel will be balck or white!
if tGray >= tThreshold then
## White
put 255 into tGray
else
## Black
put 0 into tGray
end if
put numToChar (tGray) into char (tImgPosition + 2) of tImage
put numToChar (tGray) into char (tImgPosition + 3) of tImage
put numToChar (tGray) into char (tImgPosition + 4) of tImage
end repeat
##assign the updated image data back to the displayed image
set the imageData of image "Image" to tImage
set the cHiddenImageData of image "Image" to tImage
end mouseUp
Tested and works!
Hint:
This will not turn the image into a real B/W BITMAP image, it will only change the RGB values accordingly!
Best
Klaus
Re: How Do I convert an Image to black and white?
Posted: Sat Aug 30, 2014 5:17 pm
by Fasasoftware
KLAUS...your the best!!! Fast Answer!!!!
You have solved in full my problem!!!!! I thank you really!!! I appriciate so much!!!! Vielen Danke!!!
Best Regards,
Happy Summer,
Lestroso
