Convert Colored Image to B&W

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Bantymom
Posts: 73
Joined: Fri Aug 27, 2010 4:32 am

Convert Colored Image to B&W

Post by Bantymom » Mon Feb 14, 2011 9:47 pm

Greetings,
Way back in October, I was working on a stack for the Special Education student in my classroom. I got it to the point where he could work on it and I could adjust add things on as he improved.

Now he is leaving me and going into an all-day Special Ed class where he will be much happier. I am going to send along his program (I don't know how yet because rev media is no longer available and I am sure the Sp Ed dept won' buy Live Code, but one problem at a time), and so now I need to make the interface for the teacher completely easy, everything set up and set in stone, and the stack completely clean and bug free.

Here is problem #1: Instead of having the new teacher take a colored image and use PS to make a B&W copy and then make a White & Clear image for the "chalkboard," I would like to take the colored image and replace all the non-black pixels with white. I think I saw this somewhere, which is what gave me the idea, but I can't find it again.

But I think it would go something like this:
Look at the first pixel
If it is black, go to the next.
else, make it white and go to the next
continue until the entire image has been checked.

Does that make sense?

The potential problem I see is that these images need to be squishable and expandable to fit into already set Image box things, all of which are not the same size. This is how that is currently done at the beginning of the game. The three images are currently stored on a card named for the level that corresponds to the child's level. When the game is begun, this happens:

Code: Select all

   --get and paste Chalk and Colored images to Game Card and Painting Card
   put image "ChalkDrawing" of card PaintLevel into image "ChalkDrawing" of card "Game Card"
   put image "ColoredDrawing" of card PaintLevel into image "ColoredDrawing" of card "Game Card"
   hide image "ColoredDrawing"
   put image "LineDrawing" of card PaintLevel into image "LineDrawing" of card "Painting Card"
So, I wonder if that makes them vector images and so the pixel by pixel check won't work? Or could the conversion be done after the image was pasted into place?

If this works, I might be able to store the base images somehow as custom properties (not sure how to do that yet) which would save space.

Thank you all for your patience and time,
Bantymom

example image is attached
Attachments
7Chicken-ColoredDrawing.gif
7Chicken-ColoredDrawing.gif (11.74 KiB) Viewed 3672 times
2nd-grade Teacher, Poultry Fancier, Scottish Country Dancer
and Perpetual Beginner

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: Convert Colored Image to B&W

Post by BvG » Mon Feb 14, 2011 11:19 pm

You can manipulate the imagedata, then copy the image onto your visible area. depending on size that might be too slow. Maybe there is a blendlevel that does exactly what you want?
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Convert Colored Image to B&W

Post by bn » Tue Feb 15, 2011 1:09 am

Hi BantyMom,
nice to hear from you again. Did he learn spelling with your progamm?

I upload a little stack that does the conversion. It turns everything into white which is not pure black. It works with your image. You might have images that what appears black is not 'real' black but very dark. In the code there is a comment where you could increase the cutoff. Now it is 0 = black. You could set that to a higher value. But this might be more than what you want.

There is a button that loads pictures. It does not distinguish between images and other documents. So if you inadvertendly choose a non picture document it will fail. It will also fail for images Revolution/livecode does not support. .gif, .jpg and .png is ok. There might be more.

I think you will be able to integrate the code into your programm. It is pretty straightforward. It takes the imagedata of an image and after processing sets the imagedate of that same image.

Kind regards

Bernd
Attachments
bantyImageWhite.livecode.zip
(13.3 KiB) Downloaded 269 times

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Convert Colored Image to B&W

Post by bn » Tue Feb 15, 2011 1:16 am

Hi BantyMom,
So, I wonder if that makes them vector images and so the pixel by pixel check won't work? Or could the conversion be done after the image was pasted into place?
no, an image will always be an image, i.e. pixel by pixel. No vector.
If you copy the images that is ok. Changing their size is ok.
You dont have to put them into custom properties, if you find that more complicated. Just store them in a substack or wherever and copy them from there. You dont save by putting the images into custom properties. They dont shrink by that. What I did the other day was just storing differences in imagedata in custom properties. That saves a little but would not be your case with new/different images.

Kind regards
Bernd

Post Reply