-2

i would like to color some pixels of a 16 bits grayscale image(whose maximum value is 850). First, I transformed it to a 3d stack (I) then i passed a color to it but the image don't appear in a good way.

   I = np.dstack([image, image, image])
   I[5:10, 5:10, :] = [200, 0 , 0]
   plt.figure()
   plt.imshow(I, interpolation='nearest' )

the 16 bits grayscale image after the colour changing edited It's just an example of how the image appear, the black isn't clear at all per example. iIt isn't the image of I in the code.

Community
  • 1
  • 1
Rabih Assaf
  • 95
  • 1
  • 1
  • 8
  • Are the values inside the red area `NaN`'s? – berna1111 Mar 10 '17 at 13:58
  • It's just an example it isn't the image of I in the code. no the values inside the red area aren't NaN's – Rabih Assaf Mar 10 '17 at 15:01
  • what method or basis you want for coloring? for gradient mappings you need to handle both min and max values and in some cases also the distribution of values (so you can chose linear or non linear mappings). – Spektre Mar 10 '17 at 15:38
  • I want to color using a RGB basis – Rabih Assaf Mar 10 '17 at 16:21
  • @RabihAssaf you misunderstood by basis of coloring I mean how you want to compute color from values (not which color space you need) There are many ways like 1. got predefined color gradient and just map to your values (like IR camera images) 2. values got specific physical property that is bound to specific color (like visible spectrum wavelength, or [star BV](http://stackoverflow.com/a/22630970/2521214)) 3. you want unique color for unique values 4. want to emphasize some math or physical properties of array etc there are too many possibilities so specify closer what exactly you want. – Spektre Mar 13 '17 at 08:29
  • here example for #4 [Inversing an interpolation of rotation](http://stackoverflow.com/a/41937686/2521214) It is simple and shows value sign by color, abs value by intensity and the range is changed to emphasize geometric properties (the holes) in the scan ... – Spektre Mar 13 '17 at 08:37

1 Answers1

1

Are you sure the RGB values are between 0 and 1? Using your code I made this example:

import matplotlib.pyplot as plt
import numpy as np

n_points = 100
a = np.linspace(0, 1, n_points)
b,c = np.meshgrid(a,a)
image = (b+c)/2

a_third = n_points/3.

I = np.dstack([image, image, image])#
I[a_third:2*a_third, a_third:2*a_third, :] = [1 , 0 , 0]
plt.figure()
plt.imshow(I, interpolation='nearest' )

Resulting picture with the centre in red

But if I change the example above to use values between 0 and 255 (which you seem to be doing when setting those points to [200, 0, 0]):

import matplotlib.pyplot as plt
import numpy as np

n_points = 100
a = np.linspace(0, 255, n_points)
b,c = np.meshgrid(a,a)
image = (b+c)/2

a_third = n_points/3.

I = np.dstack([image, image, image])#
I[a_third:2*a_third, a_third:2*a_third, :] = [255 , 0 , 0]
plt.figure()
plt.imshow(I, interpolation='nearest' )

enter image description here

I do think when given a value larger than 1 it will only consider its remainder when dividing by one (you can check this by changing the line image = ((b+c)/2)%1 in the last example and verifying you get the same image).

berna1111
  • 1,811
  • 1
  • 18
  • 23