The majority of forums are now only available as archives, which means posting/editing is disabled.
The Anything and Everything forum is still open.
The Anything and Everything forum is still open.
Bit Extraction
|
|||
|
Rank: Unregistered
|
Hello, If I hava an array[X][Y] , each element array[i][j] is stored in a byte conatins 0 to 7 bits , How I can create 8 arrays each one of them contain the Bit-k of array[i][j], for example, arraybit3 will contain the 3rd bits of all array[i][j] s ? Thanks in advance for any help . |
||
|
|||
|
|||
|
Rank: ? (4827)
Member #: 3416 |
here's how you'd put array[X][Y] into arraybits[8][X][Y], you should be able to adapt this to what you want:
Code:
arraybits[][][] will be filled with ones and zeros then. you would of course need to declare arraybits before doing this, and array would need to be filled. if you just want zero or nonzero, you can remove the >> k part of the assignment statment--that just shifts the bit down to the 0th bit. here's an explanation of what the assignment does: 1 << k shifts a one left k bits, to give us for k=3, 00001000. this is so we can ignore the bits that aren't 1 array[i][j] & (1 << k) this is a bitwise and, which is going to turn all the bits that are 0 in 1 << k to 0 in array[i][j], but leave the bit that's 1 in 1 << k the same as it was before. ( ... ) >> k shift the bit we might have back down to the 0th bit so the value will actually be one or zero not some power of two or zero.
my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
|
||
|
|||
|
|||
|
Rank: ? (263)
Member #: 161 |
Your question wasn't very clear, you should make a start on this by your self and post the code when you get stuck.
This should help with any bitwise problems your having: http://www.gamedev.net/reference/articles/article1563.asp
Smart people still exist and I've found where they've been hiding from me:
http://shellcity.net/phpBB/
|
||
|
|||
|
|||
|
Rank: Unregistered
|
Thank you Vmuch misterhaan, this what I want but when implementing it I get a wrong result . Maybe I did something wrong. My array contains integer values from 0 t0 255 as a grey-level image. So when ectract each value of the array , the result must be a grey-level image also. what I do is the following: 1. Code:
2. for each value of k (0..7) I wrote the following procedure.. Code:
For examle if k=3 Code:
but when drawing bit3image I got a black rectangle instead of an image !!! Why I got this result? |
||
|
|||
|
|||
|
Rank: Unregistered
|
Here is the idea behind my program: http://ysgeo.yonsei.ac.kr:8000/professor/jswon/dip/html-dip/c4/s12/front-page.html |
||
|
|||
|
|||
|
Rank: ? (4827)
Member #: 3416 |
i'm not sure even after reading the link you posted how the data should be stored in the array when you draw your bit3image, it's very possible that the code i gave you isn't storing the information in the way you need it to.
my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
|
||
|
|||
|
|||
|
Rank: Unregistered
|
Hello misterhaan, here is an illustrated picture that show my idea in clearly way I hope : [img]http://nomatterwhat.jeeran.com/array.gif[/img] Illustrated Image My original array contains integer values btween 0 to 255 I need to extract each value in the array to its 8-bits then store each bit in specified array . I set an example here 128 = 10000000. It will be extracted as follows Bitplane0[i] = 1; Bitplane1[i] = 0; Bitplane2[i] = 0; Bitplane3[i] = 0; Bitplane4[i] = 0; Bitplane5[i] = 0; Bitplane6[i] = 0; Bitplane7[i] = 0; and so on . Hope I clarify the whole idea behind my program. |
||
|
|||
|
|||
|
Rank: ? (4827)
Member #: 3416 |
well the code i posted should give you this instead:
arraybits[0][i][j] = 0; arraybits[1][i][j] = 0; arraybits[2][i][j] = 0; arraybits[3][i][j] = 0; arraybits[4][i][j] = 0; arraybits[5][i][j] = 0; arraybits[6][i][j] = 0; arraybits[7][i][j] = 1; looking at your image you have the 1 in bitplane7, so this is essentially the same thing. i believe you can set up pointers as such and get the same thing: unsigned char* Bitplane0 = arraybits; unsigned char* Bitplane1 = Bitplane0 + X * Y; unsigned char* Bitplane2 = Bitplane1 + X * Y; unsigned char* Bitplane3 = Bitplane2 + X * Y; unsigned char* Bitplane4 = Bitplane3 + X * Y; unsigned char* Bitplane5 = Bitplane4 + X * Y; unsigned char* Bitplane6 = Bitplane5 + X * Y; unsigned char* Bitplane7 = Bitplane6 + X * Y; that's assuming arraybits is declared as a 3-d array of unsigned char. if it's int or something, just make it int* instead of unsigned char* then you can access the values in Bitplane0 (and all the other BitplaneN pointers) as if it were a 2-d array: Bitplane0[x][y] if that doesn't work, you can just change the subscripts on arraybits so that it goes arraybits[i][j][k] instead of arraybits[k][i][j].
my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
|
||
|
|||
|
|||
|
Rank: Unregistered
|
The problem is solved . I did a little changes to the code to make it easier and it works correctly with me. the code is : Code:
this code will give me binary images (0s and 1s). I'm trying to apply it for 16-bits / 24-bits or 32-bits full color images but the results isn't correct . Any idea why it doesn't work with full-color images ? Waiting and thanking for any help. |
||
|
|||
|
|||
|
Rank: ? (4827)
Member #: 3416 |
full color images need more than 8 bits per pixel, so maybe that's why it wouldn't work for you
my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
|
||
|
|||
|
|||
|
Rank: Unregistered
|
Yeah, Full color images need 16 32 bits or more , so I tried to do the following : Code:
but the problems I faced are: 1) how to determine whether the image is of type 16 , 32, bits or more? 2) How to code the value of RED,Green, and Blue colors in C ? I appreciate you cooperative Misterhaan. Thank you very much. |
||
|
Please login or register to post a reply.
