# How to convert the color image into binary sequence?

7 visualizzazioni (ultimi 30 giorni)
Bhavneet Sharma il 2 Mar 2019
I am M.Tech scholar and working on watermarking. I imported color immage of size 512*512 and i want to convert that color image into binary sequence and that sequence has used in embedding of watermark.
Then, how to convert image into binary sequence?
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Walter Roberson il 2 Mar 2019
Provided that your image is not logical() [possible for some black and white images in some image formats], and is not character or string (no known image file formats) then
binary_sequence = reshape(dec2bin(typecast(YourImage, 'uint8'), 8) - '0', 1, []);
This will not have any watermark embedded in it: this is what you use to get a binary sequence of the watermark in preparation for embedding it into an image.
The way to embed bits in an image depends upon your embedding technique and data class, but often involves bitset()
##### 2 CommentiMostra NessunoNascondi Nessuno
Bhavneet Sharma il 3 Mar 2019
thanku you!!
can you explain why you "-'0', 1,[]" put in the reshape function?
Walter Roberson il 3 Mar 2019
The output of dec2bin() of uint8 with 8 as its second argument is going to be a something by 8 character vector of characters '0' and '1' . When you subtract '0' from that you get the offset from '0', which will be numeric 0 (if the character was '0') or numeric 1 (if the character was '1'). So after subtracting, the character array of '0' and '1' will be changed to a something by 8 numeric array of 0 and 1 values.
reshape(values, 1, []) converts the something by 8 numeric array into a 1 by (something*8) numeric array -- a row vector.
Note that the bits for any particular input value might end up separated by a fair bit: this particular code does not attempt to hold together the bits that were originally together. To do that you would .' before the reshape()

Accedi per commentare.

### Più risposte (2)

gonzalo Mier il 2 Mar 2019
I suppose you have a filter of color of [100,150,30], so to convert the image M you can do:
sol = squeeze( M(:,:,1) > 100 & M(:,:,2) > 150 & M(:,:,3) > 30 )
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Walter Roberson il 2 Mar 2019
This would be a form of conversion from color to black and white, which is not what was being asked about.

Accedi per commentare.

Image Analyst il 2 Mar 2019
I do that in my attached demo.
For more info, click the tag on the right that says "watermark".
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Watermarking in Help Center e File Exchange

R2018a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by