DSPRelated.com
Forums

how to convert image in to binary bits sequence

Started by ahali February 18, 2007
  i m doing a project in image watermarking .any of you guys know that   
how to convert image in to binary bits sequence .
 i have tried this simple code ,
 a=imread('lena.jpg');
 b= round(a./256)
   but i got binary bits like this=
     column 1 to some columns
   1 0 1 0 0 1 0 0 0 0
   0 0 0 1 0 1 0 1 0 0
        . 
        .
        .                     
    
   1 0 0 0 0 0 0 0 0 0 
   0 1 0 1 0 1 0 1 0 0 
        . 
        .
  columns some numbers to 256
   1 0 1 0 1 0
   0 0 0 0 0 0 
   

  but what i want is row vector in this way b = (1 0 1 0 1 0 0 0 .....n)
   i tried to use reshape and transpose  but failed to get like what i
want . 
   so please any of you huys give me hint or if u have some source code
  thanks in advance
   


ahali wrote:
> i m doing a project in image watermarking .any of you guys know that > how to convert image in to binary bits sequence . > i have tried this simple code , > a=imread('lena.jpg'); > b= round(a./256) > but i got binary bits like this= > column 1 to some columns > 1 0 1 0 0 1 0 0 0 0 > 0 0 0 1 0 1 0 1 0 0 > . > . > . > > 1 0 0 0 0 0 0 0 0 0 > 0 1 0 1 0 1 0 1 0 0 > . > . > columns some numbers to 256 > 1 0 1 0 1 0 > 0 0 0 0 0 0 > > > but what i want is row vector in this way b = (1 0 1 0 1 0 0 0 .....n) > i tried to use reshape and transpose but failed to get like what i > want . > so please any of you huys give me hint or if u have some source code > thanks in advance
Every digital image is a pile of bits. You need to know the encoding format of your particular picture to make sense of them. .jpg files are compressed and need to be decoded before an image can be displayed. The code isn't secret, but unless you know it, it might as well be. Jerry P.S. Lena had three kids in her native Sweden last I heard. The face in the digitized Playboy centerfold of her has long been used as a test image for compression algorithms. See http://ndevilla.free.fr/lena/ and http://www.cs.cmu.edu/~chuck/lennapg/lenna.shtml -- Engineering is the art of making what you want from things you can get. ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
On Feb 18, 5:57 pm, Jerry Avins <j...@ieee.org> wrote:

<snip>

> Every digital image is a pile of bits. You need to know the encoding > format of your particular picture to make sense of them. .jpg files are > compressed and need to be decoded before an image can be displayed. The > code isn't secret, but unless you know it, it might as well be. > > Jerry > > P.S. Lena had three kids in her native Sweden last I heard. The face in > the digitized Playboy centerfold of her has long been used as a test > image for compression algorithms. Seehttp://ndevilla.free.fr/lena/andhttp=
://www.cs.cmu.edu/~chuck/lennapg/lenna.shtml
> -- > Engineering is the art of making what you want from things you can get. > =AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=
=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF= =AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF- Hide qu= oted text -
>
.=2E.And such a lovely pile of bits... Ken
>On Feb 18, 5:57 pm, Jerry Avins <j...@ieee.org> wrote: > ><snip> > >> Every digital image is a pile of bits. You need to know the encoding >> format of your particular picture to make sense of them. .jpg files
are
>> compressed and need to be decoded before an image can be displayed.
The
>> code isn't secret, but unless you know it, it might as well be. >> >> Jerry >> >> P.S. Lena had three kids in her native Sweden last I heard. The face
in
>> the digitized Playboy centerfold of her has long been used as a test >> image for compression algorithms.
Seehttp://ndevilla.free.fr/lena/andhttp=
>://www.cs.cmu.edu/~chuck/lennapg/lenna.shtml >> -- >> Engineering is the art of making what you want from things you can
get.
>>
=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=
>=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF= >=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF- Hide
qu=
>oted text - >> > >.=2E.And such a lovely pile of bits...
>Ken
> >Inshort what i want to say is , i have image X N by N. N=12. i want touse
Image X as binary watermark after converting Image X in to bit stream and representign in row vector in this way , say Wm = (1 0 1 0 1 ....L) l is length of Wm. so how to manage it?
>
ahali wrote:

   ...

> In short what i want to say is , i have image X N by N. N=12. i want to use > Image X as binary watermark after converting Image X in to bit stream and > represention in row vector in this way , say Wm = (1 0 1 0 1 ....L) l is > length of Wm. so how to manage it?
There are at two free utilities on Sourceforge for converting jpeg images to raw form. You may want to start there. Jerry -- Engineering is the art of making what you want from things you can get. &macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;
hi,

i would be much easier if you could get lena.bmp form the net... or any
.bmp file. or open your lena.jpg in a photo editor and save it as a bmp.
once you get the .bmp file remove the header (54 bytes) and you can read
the rest of the data as GBR (one byte for each colour). you can get a lot
of info form the net on the .bmp file format. you can try out all kinds of
image processing on that GBR data extracted from the file.. this will save
you from a lot of decoding-encoding hassle. it processing much
easier...(atleast in c)


APS








> i m doing a project in image watermarking .any of you guys know that
>how to convert image in to binary bits sequence . > i have tried this simple code , > a=imread('lena.jpg'); > b= round(a./256) > but i got binary bits like this= > column 1 to some columns > 1 0 1 0 0 1 0 0 0 0 > 0 0 0 1 0 1 0 1 0 0 > . > . > . > > 1 0 0 0 0 0 0 0 0 0 > 0 1 0 1 0 1 0 1 0 0 > . > . > columns some numbers to 256 > 1 0 1 0 1 0 > 0 0 0 0 0 0 > > > but what i want is row vector in this way b = (1 0 1 0 1 0 0 0 .....n) > i tried to use reshape and transpose but failed to get like what i >want . > so please any of you huys give me hint or if u have some source code > thanks in advance > > > >

salaria wrote:

> hi, > > i would be much easier if you could get lena.bmp form the net... or any > bmp file. or open your lena.jpg in a photo editor and save it as a bmp.
The results are going to be incorrect, because the unpacked jpeg is different from the original image. The loseless format like bmp, pcx or gif should be used as the source. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
>> but what i want is row vector in this way b = (1 0 1 0 1 0 0 0 .....n) >> i tried to use reshape and transpose but failed to get like what i >>want . >> so please any of you huys give me hint or if u have some source code >> thanks in advance
I don't understand the function of converting the image into a bit stream, working with images at bit level isn't very efficient, if the original image is using 32bit colour (Red, Green, Blue, Alpha),after you have uncompressed the image in raw format, I would be tempted to work with each colour as unsigned long variables, any bit operations you needed to do would be accomplished using binary function operators and shift operators and hexdecimal numbers.