#### Archived

This topic is now archived and is closed to further replies.

# Bit Extraction

This topic is 5301 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I used the following code to BitPlane Slicing for 8-Bits gray-level Image :
unsigned char mask = 0x1 << plane  // plane will take values from (0-7) (8 bits)

For (i = 0; i
The result of the previous code is 8 binary images.
The original image is an array of type unsigned char.
Now,I need to extend the code to 16 bits. It means, if I have an image of type short and we want to display the image as a set of bit-images not gray level, How could I re-code to get what I want . I try alot and comes up with some uncorrect results.
Who can help in re-coding "My Code" ?
Thanks in advance for any cooperative.
[Edit: The simple solution is not to use "i" for indexing.]
[edited by - Oluseyi on April 10, 2004 4:01:59 PM]


##### Share on other sites
I don''t get what you mean. In your current scheme, parallel bits in the image array represent a 1-bit image. Since you have type unsigned char, you have eight images. If you keep the schematic, then changing the type to unsigned short only increases the number of 1-bit images you will have (sixteen), but not the fact that they are all 1-bit images.

##### Share on other sites

Yeah, I know that changing from unsigned char to unsigned short will change the output from ( 8 binary images ) to ( 16 binary images)

But the problem is in gray level image it is simple because I used one mask and assigned the values either to 255 ( white ) or ( 0 ) black . But with full color image of type short what the mask will be ? .

##### Share on other sites

I need a really urgent help on my problem pls . I don''t know if I clarify what I want exactly or not but I reexplain the problem as an semi-algorithms:

Input : a full color image (16-bits) represented in the program as an array of type unsigned short [Xsize][Ysize]

Output:
16 (1-bit) images

Process:
unsigned char mask = 0x1 << plane
For (i = 0; iFor( j = 0; j if (image[ i ][ j ] & mask) display[ i ][ j ] = 255; else display[ i ][ j ] = 0;

With lots/less of modification .

I''m running out of time and still have no result despite my trying to have.

Any help with many thanks in advance.

##### Share on other sites
Shouldn''t
unsigned short mask = 0x1 << plane;
do it?
AND operation works with short variables as well as with chars.

##### Share on other sites

Yes , "unsigned char mask = 0x1 << plane " can do it easily but what I will get is 16 (1-Bit)-binary images , Binary image means that it have either 0 (Black) or 1 (White), what I want is : since the original image is full color image , shouldn''t I have 16 (1-Bit)-Colored images , what I mean by "colored" is ambiguous to me since I don''t know how to extract the three colors (Red,Green,Blue)?

##### Share on other sites
quote:
Original post by BusyBee
since the original image is full color image , shouldn''t I have 16 (1-Bit)-Colored images , what I mean by "colored" is ambiguous to me since I don''t know how to extract the three colors (Red,Green,Blue)?

16-bit images are usually stored in 555 or 565 RGB format. Meaning the first 5 bits of each pixel are red, the next 5 or 6 are green, and the next 5 are blue. I''m not entirely sure what you want to acheive, but if you want your final images to be 16-bit black and white, then you need to set all the bits of the white pixels to 1. For a 565 format this will be 0xFFFF, for a 555 it will be 0x7FFF or 0xFFFE, not sure which one.

Michael K.,
Co-designer and Graphics Programmer of "The Keepers"

We come in peace... surrender or die!

##### Share on other sites
quote:
Binary image means that it have either 0 (Black) or 1 (White), what I want is : since the original image is full color image , shouldn't I have 16 (1-Bit)-Colored images , what I mean by "colored" is ambiguous to me since I don't know how to extract the three colors (Red,Green,Blue)?

A 1-bit image only has two colors. Normally these are white and black (or sometimes white and transparent). You can have these two colors be anything you want really (red and blue, green and yellow, purple and cyan, etc.) but the fact remains that you only have two. There's only enough information in one bit for two states. The most important thing to remember here is that an "image" only comes about through certain interpretations of the data, and that there is nothing inherent about the data itself that makes it image, other than how you process it. So don't get stuck in the mode of thinking where since you start with what you know to be a color image, you somehow have to end up with color images through clever algorithmic tricks. It isn't necessarily so.

Given the nature of your algorithm there is no way to extract any additional information from your source image. The fact that your source data is ironically an image makes no difference; you interpret the data completely differently. Take your first example. You have an image of size MxN bytes. Each byte has eight bits, which corresponds to eight 1-bit images. In the end, you will generate M*N*8 1-bit images. You output just as much information as you input. Now let's say you have MxN shorts. Each short has sixteen bits, which corresponds to sixteen 1-bit images. In the end, you want to generate M*N*16 1-bit images. But that's all you can. Your output is the same amount of information as your input. There's nothing more.

From a purely mathematical perspective, you can modify the algorithm in several ways to get what you want. For example, if you want to output 16-bit images, which will give you a good range of colors, you can only output M*N images. If you want 8-bit images, then you can only generate M*N*2 of them. It all depends how interpret the data you're given.

[edited by - Zipster on April 12, 2004 4:09:02 AM]

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 13
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
632927
• Total Posts
3009243
• ### Who's Online (See full list)

There are no registered users currently online

×