TheMeaningfulEngineer
TheMeaningfulEngineer

Reputation: 16359

How are non integer images represented?

Intro

To the computer, digital grayscale images are represented as integer matrices where the maximim number (which is dependent on the integer precision) represents black an 0 is white.

enter image description here

Here is a representation of an image which for integers, and when cast to floats.

enter image description here

int
array([[6, 1, 1, 0, 6, 4],
       [0, 1, 2, 7, 5, 2],
       [0, 4, 6, 6, 3, 4],
       [1, 1, 2, 6, 7, 0],
       [3, 6, 6, 5, 5, 3]])

float
array([[ 6.,  1.,  1.,  0.,  6.,  4.],
       [ 0.,  1.,  2.,  7.,  5.,  2.],
       [ 0.,  4.,  6.,  6.,  3.,  4.],
       [ 1.,  1.,  2.,  6.,  7.,  0.],
       [ 3.,  6.,  6.,  5.,  5.,  3.]])

Question

I've been working with svd, and as a result, a get an image whose matrix representation consists of floats. It gets printed fine with imshow from matplotlib.

How does the 'brightness to value' mapping works when the grayscale image values are floats?

Upvotes: 1

Views: 822

Answers (2)

tacaswell
tacaswell

Reputation: 87536

matplotlib maps values to colors using the colormap (doc) class (and it's sub-classes) and the Normalize (doc) class (and it's sub-classes). The basic idea is that normalize converts what ever input you give it to floats in the range of [0, 1]. There are a variety of linear and non-linear ways to do this (implementing gamma correction for example) The colormap class then coverts scalars in the range [0, 1] -> rgb values, and can do that by any mapping you want (gallery)

Upvotes: 1

Vicky
Vicky

Reputation: 13244

According to http://www.weizmann.ac.il/matlab/toolbox/images/imshow.html

imshow(I,n) displays the intensity image I with n discrete levels of gray. If you omit n, imshow uses 256 gray levels on 24-bit displays, or 64 gray levels on other systems.

imshow(I,[low high]) displays I as a grayscale intensity image, specifying the data range for I. The value low (and any value less than low) displays as black, the value high (and any value greater than high) displays as white, and values in between display as intermediate shades of gray. imshow uses the default number of gray levels. If you use an empty matrix ([]) for [low high], imshow uses [min(I(:)) max(I(:))]; the minimum value in I displays as black, and the maximum value displays as white.

imshow(BW) displays the binary image BW. Values of 0 display as black, and values of 1 display as white.

So it depends how you are calling imshow() as to how it interprets the image for display. If you are calling it with an empty matrix for [low,high] it will just use whatever the max and min values in the array are.

Upvotes: 1

Related Questions