Image Binarization - Techist - Tech Forum

Go Back   Techist - Tech Forum > Computer Software > Microsoft Windows and Software
Closed Thread
Thread Tools Display Modes
Old 07-13-2005, 12:05 PM   #1 (permalink)
Newb Techie
Join Date: Feb 2005
Posts: 11
Default Image Binarization

I load an image, convert it to bitmapData using the 24bppRGB pixel format, binarize it using a simple routine (shown below) and save it using the Image.Save() method. The image saved however is still 24bppRGB - although all colours have the same value, either 0 or 255 - and shows up as an RGB image in Photoshop.

Any ideas on how I can change it to binary, ie a 1bpp format?


Bitmap bMap=new Bitmap (iMage);
BitmapData bData = bMap.LockBits(new Rectangle(0, 0, bMap.Width, bMap.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
System.IntPtr Scan0 = bData.Scan0;
int iStride=bData.Stride;
int iht=bMap.Height;
int iwd=bMap.Width;
int iPix=new int[iht][];
byte *p = (byte*)(void*)Scan0;
int nOffset = iStride-iwd*3;
for(int y=0;y<iht;++y)
iPix[y]=new int[iwd];
for(int x=0;x<iwd;++x)
if (conditionA) p[0]=p[1]=p[2]=0;
else p[0]=p[1]=p[2]=255;
p += 3;
p += nOffset;

sarabjit is offline  
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Our Communities

Our communities encompass many different hobbies and interests, but each one is built on friendly, intelligent membership.

» More about our Communities

Automotive Communities

Our Automotive communities encompass many different makes and models. From U.S. domestics to European Saloons.

» More about our Automotive Communities

Marine Communities

Our Marine websites focus on Cruising and Sailing Vessels, including forums and the largest cruising Wiki project on the web today.

» More about our Marine Communities

Copyright 2002-2015 Social Knowledge, LLC All Rights Reserved.

All times are GMT -5. The time now is 02:28 PM.

Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2016, vBulletin Solutions, Inc.