converting bmp image to double vector ?

I need to convert .bmp image to double vector, I will use these vectors for training neural network. I did the following :
img = imread('test.bmp');
number=im2double(img);
number = number';
data=number(:);
but the resulted vector (data) has 1938 binary values (0 and 1). when I tried the same code for jpg image It gave me vector with 256 double values. what is the difference between jpg and bmp in this case ? note the bmp image is actually image for number which is black and background is white. but the jpg image has white number on black background

5 comentarios

Geoff Hayes
Geoff Hayes el 10 de En. de 2015
Editada: Geoff Hayes el 10 de En. de 2015
Fatma - what can you say about the test.bmp? What do you observe when you run the unique command
img = imread('test.bmp');
unique(img)
What can you say about the numbers that are returned from the above command? Now repeat this for the jpeg. What do you notice?
Fatma Zamil
Fatma Zamil el 10 de En. de 2015
test.bmp unique values are 0 and 1 but for the jpeg unique values are numbers from 0 to 255 I'm training a neural networks, I saw example on internet, when they converted their training images they had vector for each image with double 256 value but in my case (i have bmp images) I got binary vector with 1938 value so I got confused !!
Image Analyst
Image Analyst el 10 de En. de 2015
Fatma, please attach both the BMP and the JPG images (like people usually do when they ask for advice on image processing).
Fatma Zamil
Fatma Zamil el 10 de En. de 2015
I attached the images, thank u for ur advise
Fatma Zamil
Fatma Zamil el 10 de En. de 2015
do any one know how I can convert different bmp images to vectors with same number of elements ! when I tried converting 2 bmp images as I did above in my code, the resulted vectors are different in size !

Iniciar sesión para comentar.

Respuestas (2)

Image Analyst
Image Analyst el 10 de En. de 2015

0 votos

JPEG is a lossy compression, so it basically will blur the image and introduce gray levels and colors that are not in the original non-lossy image (like BMP, TIFF, or PNG). That is why the JPG image has more gray levels than the BMP version.

1 comentario

"how I can convert different bmp images to vectors with same number of elements"
vector = bmpImage(:);
The number of elements and number of colors or gray levels in vector will be the same as in the variable bmpImage.
Also, the number of rows and columns in a variable read in from a JPG image file will equal the number of rows and columns in a variable read in from a BMP format file (same image, just different file formats). However the number of color channels may be different - sometimes the JPG image reads in as a color image (3 channels or planes) even though it appears to you to be a gray scale or binary image. And the number of gray scales or colors may be different for a JPG image than a BMP, TIF, or PNG image because of lossy JPG artifacts - the block artifacts that I'm sure you've seen in heavily compressed images.

Iniciar sesión para comentar.

Guillaume
Guillaume el 10 de En. de 2015

0 votos

There is a field in a the bitmap file that indicates how many colours are encoded in the file, it can be 2, 16, 256, 2^16, 2^24 or 2^32. Your bitmap obviously only has 2 colours while the ones you saw in examples had more.
JPEG images always have at least 256 colours (they could all be the same). Furthermore, if you took a 2 colours bitmap and encoded it as a jpeg you'd get more than two colours due to the way jpeg encodes colours.

1 comentario

Image Analyst
Image Analyst el 10 de En. de 2015
First paragraph - not necessarily. It could still be an 8 bit grayscale image or even an RGB image even though it has pixel values of only 0 and 1.

Iniciar sesión para comentar.

Categorías

Más información sobre Deep Learning Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 9 de En. de 2015

Comentada:

el 10 de En. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by