Re: drawing 1 bit images, and image resolution
Re: drawing 1 bit images, and image resolution
- Subject: Re: drawing 1 bit images, and image resolution
- From: Graham Cox <email@hidden>
- Date: Fri, 10 Feb 2012 09:43:01 +1100
On 10/02/2012, at 3:54 AM, Chris Paveglio wrote:
> still looking for a way to convert to 1-bit.
So what have you tried?
There are a lot of different methods for deciding how to threshold an image - in other words how to decide which colours end up as 1s and which as 0s. You will probably find that a 50% cut based on brightness is too simplistic, and the results will be very disappointing. For good results you will usually have to quantize the colour image into a smaller set of colours using some statistical method, for example popular 555, or octree. This is a whole art in itself, and quite complex. You might get away with first converting to an 8-bit greyscale image and thresholding that - at least you can do a greyscale conversion easily. The old Mac OS used to have API for doing colour quantization, but Cocoa does not.
But actually performing the thresholding isn't hard - just walk the bitmap, look at the (quantized) pixel value and if its above the threshold, set a 1, below set a 0. It's probably best to set the pixel in a second bitmap rather than do it in place. I recommend designing your code so that you can experiment with both the weighting of RGB values to determine brightness, and the threshold level itself. If you don't the result is certain to disappoint, and end up much blacker than you expected.
You can use NSBitmapImageRep's getPixel:atX:y: to read the source pixel and setPixel:atX:y: to set the destination pixel in a x,y double loop. Note that pixel values used by these methods are not colours.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden