![]() image = image.astype('uint8')Įquivalently, and more efficiently, you may also bit-shift the 16-bit values 8 bits to the right: image = (image > 8).astype('uint8') Its data type must be explicitly cast to 8-bit integer in order to drop any fractions. This will yield an array of floating-point pixel values. So divide by 256 (= 2 8): image = image / 256 They need to be coerced to the 8-bit range: 0 to 255 (= 2 8−1). Side note: As there are three color channels, each sampled with a 16-bit resolution, the color depth of the image is more commonly described as "48 bits" (per pixel).ġ6-bit integer numbers range between 5 (= 2 16−1). Its dtype (data type) should be uint16, meaning unsigned 16-bit integers. You should expect your images to have a shape of (y, x, 3), where y is the number of pixels in the vertical, x in the horizontal direction, and 3 represents the three color channels: red, green, blue. The data structure in which you'll receive the pixel data is a NumPy array. You would read in the image, say example.tif, like so: import imageioĪs for the conversion, that's just basic math. ![]() That is: It may not deal correctly with images defining a color space other than the standard sRGB, or it might fail to preserve the image's intended orientation. ![]() Only caveat: It may ignore the image's meta data. As the name suggests, its singular goal is to input/output images. Generally, when you want to read or write images in Python - of any bit-depth and format - it is best to use ImageIO. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |