converting bmp image to double vector ?
4 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Image Analyst
on 10 Jan 2015
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 Comment
Image Analyst
on 10 Jan 2015
"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.
Guillaume
on 10 Jan 2015
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 Comment
Image Analyst
on 10 Jan 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.
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!