Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading bmp files in Python

Is there a way to read in a bmp file in Python that does not involve using PIL? PIL doesn't work with version 3, which is the one I have. I tried to use the Image object from graphics.py, Image(anchorPoint, filename), but that only seems to work with gif files.

like image 668
Xinnamin Avatar asked May 03 '12 20:05

Xinnamin


People also ask

How do I read a BMP file in python?

Anyway using a C library to load BMP may work e.g. http://code.google.com/p/libbmp/ or http://freeimage.sourceforge.net/, and C libraries can be easily called from python e.g. using ctypes or wrapping it as a python module.

How do I view a BMP file?

If you use a PC or Mac, start by opening the folder with the BMP file you want to use. Right-click on the file name and then hover over the Open With option. You can then choose from any number of applications to display your BMP file. These may include Adobe Photoshop, Windows Photos, Apple Photos, and more.

What is a BMP file?

Short for Bitmap Image file, BMP is an image file format that contains bitmap graphics data. BMP images are device independent and require no graphics adapter to display them. Image data in BMP files are usually uncompressed or compressed with a lossless compression.


1 Answers

In Python it can simply be read as:

import os
from scipy import misc
path = 'your_file_path'
image= misc.imread(os.path.join(path,'image.bmp'), flatten= 0)

## flatten=0 if image is required as it is 
## flatten=1 to flatten the color layers into a single gray-scale layer
like image 67
Ashish Avatar answered Sep 18 '22 15:09

Ashish