
Hi, I 'd like to modify continuously a pure red image to get an orange, yellow, green, light blue, blue, purple image. The idea is to convert a rgb image, to convert it into hsv color space, to modify the hue value then to back convert into rgb color space. The problem is that only green and blue can be obtained but no intermediate color: <https://lh4.googleusercontent.com/-s_Acsx0EmRY/UylefCuSGnI/AAAAAAAABsQ/T7pAI...> According to adobe<http://dba.med.sc.edu/price/irf/Adobe_tg/models/hsb.html>, adding a hue equal to 36 should yield a yellow image. *Here's the code:* from skimage import io from skimage import color from scipy import ndimage as nd import numpy as np from matplotlib import pyplot as plt import os cy55 = io.imread('/home/jeanpat/MFISH/PSI/P07/01/Cy5/P070109C.tif') zero = np.zeros(cy55.shape,dtype=np.uint8) rgb0 = np.dstack([cy55, zero,zero]) hue_rotations = [18, 36,72,90,108] images = {} images[0] = rgb0 hsv0 = color.rgb2hsv(rgb0) for hue in hue_rotations: hsv = np.copy(hsv0) hsv[:,:,0] = hsv[:,:,0]+ hue rgb = color.hsv2rgb(hsv) images[hue] = rgb Any greyscaled image should be ok but the image used here is: <https://lh5.googleusercontent.com/-whwEGZWWhIE/UylgLDhf0VI/AAAAAAAABsc/02kl9...>

Le mercredi 19 mars 2014 10:16:45 UTC+1, Jean-Patrick Pommier a écrit :
Hi, I 'd like to modify continuously a pure red image to get an orange, yellow, green, light blue, blue, purple image. The idea is to convert a rgb image, to convert it into hsv color space, to modify the hue value then to back convert into rgb color space. The problem is that only green and blue can be obtained but no intermediate color:
<https://lh4.googleusercontent.com/-s_Acsx0EmRY/UylefCuSGnI/AAAAAAAABsQ/T7pAI...>
According to adobe<http://dba.med.sc.edu/price/irf/Adobe_tg/models/hsb.html>, adding a hue equal to 36 should yield a yellow image.
*Here's the code:*
from skimage import io from skimage import color from scipy import ndimage as nd import numpy as np from matplotlib import pyplot as plt import os
cy55 = io.imread('/home/jeanpat/MFISH/PSI/P07/01/Cy5/P070109C.tif')
zero = np.zeros(cy55.shape,dtype=np.uint8) rgb0 = np.dstack([cy55, zero,zero])
hue_rotations = [18, 36,72,90,108] images = {} images[0] = rgb0 hsv0 = color.rgb2hsv(rgb0) for hue in hue_rotations: hsv = np.copy(hsv0) hsv[:,:,0] = hsv[:,:,0]+ hue rgb = color.hsv2rgb(hsv) images[hue] = rgb
The code to display the images is:
i = 1 plt.figure(num=None, figsize=(15, 5), facecolor='w', edgecolor='k') for hue in np.sort(images.keys()): plt.subplot(1,6,i,xticks=[],yticks=[]) plt.title('hue='+str(hue)) plt.imshow(images[hue]) i = i +1 plt.show() Any greyscaled image should be ok but the image used here is:
<https://lh5.googleusercontent.com/-whwEGZWWhIE/UylgLDhf0VI/AAAAAAAABsc/02kl9...>

Hi Jean-Patrick, There are a few possible issues. One is simply a difference in data type. The angles you describe go from 0-to-180, but in scikit-image's representation of these images, it goes from 0-to-1. Also, you're only passing the red channel to the rgb image. I'm not sure what effect that has on the final result. In any case, I think the example below might be closer to what you're after. Best, -Tony #--- import numpy as np import matplotlib.pyplot as plt from skimage import color from skimage import data def colorize(image, hue): """Return image tinted by the given hue based on a grayscale image.""" hsv = color.rgb2hsv(color.gray2rgb(image)) hsv[:, :, 0] = hue hsv[:, :, 1] = 1 # Turn up the saturation; we want the color to pop! return color.hsv2rgb(hsv) image = data.camera()[::2, ::2] hue_rotations = np.linspace(0, 1, 6) # 0--1 is equivalent to 0--180 colorful_images = [colorize(image, hue) for hue in hue_rotations] fig, axes = plt.subplots(nrows=2, ncols=3) for ax, array in zip(axes.flat, colorful_images): ax.imshow(array, vmin=0, vmax=1) ax.set_axis_off() plt.show() On Wed, Mar 19, 2014 at 4:20 AM, Jean-Patrick Pommier < jeanpatrick.pommier@gmail.com> wrote:
Le mercredi 19 mars 2014 10:16:45 UTC+1, Jean-Patrick Pommier a écrit :
Hi, I 'd like to modify continuously a pure red image to get an orange, yellow, green, light blue, blue, purple image. The idea is to convert a rgb image, to convert it into hsv color space, to modify the hue value then to back convert into rgb color space. The problem is that only green and blue can be obtained but no intermediate color:
<https://lh4.googleusercontent.com/-s_Acsx0EmRY/UylefCuSGnI/AAAAAAAABsQ/T7pAI...>
According to adobe<http://dba.med.sc.edu/price/irf/Adobe_tg/models/hsb.html>, adding a hue equal to 36 should yield a yellow image.
*Here's the code:*
from skimage import io from skimage import color from scipy import ndimage as nd import numpy as np from matplotlib import pyplot as plt import os
cy55 = io.imread('/home/jeanpat/MFISH/PSI/P07/01/Cy5/P070109C.tif')
zero = np.zeros(cy55.shape,dtype=np.uint8) rgb0 = np.dstack([cy55, zero,zero])
hue_rotations = [18, 36,72,90,108] images = {} images[0] = rgb0 hsv0 = color.rgb2hsv(rgb0) for hue in hue_rotations: hsv = np.copy(hsv0) hsv[:,:,0] = hsv[:,:,0]+ hue rgb = color.hsv2rgb(hsv) images[hue] = rgb
The code to display the images is:
i = 1 plt.figure(num=None, figsize=(15, 5), facecolor='w', edgecolor='k') for hue in np.sort(images.keys()): plt.subplot(1,6,i,xticks=[],yticks=[]) plt.title('hue='+str(hue)) plt.imshow(images[hue]) i = i +1 plt.show()
Any greyscaled image should be ok but the image used here is:
<https://lh5.googleusercontent.com/-whwEGZWWhIE/UylgLDhf0VI/AAAAAAAABsc/02kl9...>
--
You received this message because you are subscribed to the Google Groups "scikit-image" group. To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.

<https://lh5.googleusercontent.com/-tYhHDFsj2cM/UyqfVvwM_nI/AAAAAAAABtE/wGITF...> Now it's clear for me, thank you for your code! jp Le mercredi 19 mars 2014 10:16:45 UTC+1, Jean-Patrick Pommier a écrit :
Hi, I 'd like to modify continuously a pure red image to get an orange, yellow, green, light blue, blue, purple image. The idea is to convert a rgb image, to convert it into hsv color space, to modify the hue value then to back convert into rgb color space. The problem is that only green and blue can be obtained but no intermediate color:
<https://lh4.googleusercontent.com/-s_Acsx0EmRY/UylefCuSGnI/AAAAAAAABsQ/T7pAI...>
According to adobe<http://dba.med.sc.edu/price/irf/Adobe_tg/models/hsb.html>, adding a hue equal to 36 should yield a yellow image.
*Here's the code:*
from skimage import io from skimage import color from scipy import ndimage as nd import numpy as np from matplotlib import pyplot as plt import os
cy55 = io.imread('/home/jeanpat/MFISH/PSI/P07/01/Cy5/P070109C.tif')
zero = np.zeros(cy55.shape,dtype=np.uint8) rgb0 = np.dstack([cy55, zero,zero])
hue_rotations = [18, 36,72,90,108] images = {} images[0] = rgb0 hsv0 = color.rgb2hsv(rgb0) for hue in hue_rotations: hsv = np.copy(hsv0) hsv[:,:,0] = hsv[:,:,0]+ hue rgb = color.hsv2rgb(hsv) images[hue] = rgb
Any greyscaled image should be ok but the image used here is:
<https://lh5.googleusercontent.com/-whwEGZWWhIE/UylgLDhf0VI/AAAAAAAABsc/02kl9...>

<https://lh3.googleusercontent.com/-XZbiua42-VA/Uyr_pGIEHqI/AAAAAAAABtU/rTheR...> The different spectral components can be combined into one rgb image<http://nbviewer.ipython.org/gist/jeanpat/9665267>to yield: Le jeudi 20 mars 2014 09:00:48 UTC+1, Jean-Patrick Pommier a écrit :
<https://lh5.googleusercontent.com/-tYhHDFsj2cM/UyqfVvwM_nI/AAAAAAAABtE/wGITF...> Now it's clear for me, thank you for your code!
jp
Le mercredi 19 mars 2014 10:16:45 UTC+1, Jean-Patrick Pommier a écrit :
Hi, I 'd like to modify continuously a pure red image to get an orange, yellow, green, light blue, blue, purple image. The idea is to convert a rgb image, to convert it into hsv color space, to modify the hue value then to back convert into rgb color space. The problem is that only green and blue can be obtained but no intermediate color:
<https://lh4.googleusercontent.com/-s_Acsx0EmRY/UylefCuSGnI/AAAAAAAABsQ/T7pAI...>
According to adobe<http://dba.med.sc.edu/price/irf/Adobe_tg/models/hsb.html>, adding a hue equal to 36 should yield a yellow image.
*Here's the code:*
from skimage import io from skimage import color from scipy import ndimage as nd import numpy as np from matplotlib import pyplot as plt import os
cy55 = io.imread('/home/jeanpat/MFISH/PSI/P07/01/Cy5/P070109C.tif')
zero = np.zeros(cy55.shape,dtype=np.uint8) rgb0 = np.dstack([cy55, zero,zero])
hue_rotations = [18, 36,72,90,108] images = {} images[0] = rgb0 hsv0 = color.rgb2hsv(rgb0) for hue in hue_rotations: hsv = np.copy(hsv0) hsv[:,:,0] = hsv[:,:,0]+ hue rgb = color.hsv2rgb(hsv) images[hue] = rgb
Any greyscaled image should be ok but the image used here is:
<https://lh5.googleusercontent.com/-whwEGZWWhIE/UylgLDhf0VI/AAAAAAAABsc/02kl9...>

This would make a nice example IMO, at least an ipython notebook if not something on the gallery page. It's simple, and I've seen other examples on stack overflow with people struggling to get the transformations down in HSV space. On Thursday, March 20, 2014 10:48:22 AM UTC-4, Jean-Patrick Pommier wrote:
<https://lh3.googleusercontent.com/-XZbiua42-VA/Uyr_pGIEHqI/AAAAAAAABtU/rTheR...> The different spectral components can be combined into one rgb image<http://nbviewer.ipython.org/gist/jeanpat/9665267>to yield:
Le jeudi 20 mars 2014 09:00:48 UTC+1, Jean-Patrick Pommier a écrit :
<https://lh5.googleusercontent.com/-tYhHDFsj2cM/UyqfVvwM_nI/AAAAAAAABtE/wGITF...> Now it's clear for me, thank you for your code!
jp
Le mercredi 19 mars 2014 10:16:45 UTC+1, Jean-Patrick Pommier a écrit :
Hi, I 'd like to modify continuously a pure red image to get an orange, yellow, green, light blue, blue, purple image. The idea is to convert a rgb image, to convert it into hsv color space, to modify the hue value then to back convert into rgb color space. The problem is that only green and blue can be obtained but no intermediate color:
<https://lh4.googleusercontent.com/-s_Acsx0EmRY/UylefCuSGnI/AAAAAAAABsQ/T7pAI...>
According to adobe<http://dba.med.sc.edu/price/irf/Adobe_tg/models/hsb.html>, adding a hue equal to 36 should yield a yellow image.
*Here's the code:*
from skimage import io from skimage import color from scipy import ndimage as nd import numpy as np from matplotlib import pyplot as plt import os
cy55 = io.imread('/home/jeanpat/MFISH/PSI/P07/01/Cy5/P070109C.tif')
zero = np.zeros(cy55.shape,dtype=np.uint8) rgb0 = np.dstack([cy55, zero,zero])
hue_rotations = [18, 36,72,90,108] images = {} images[0] = rgb0 hsv0 = color.rgb2hsv(rgb0) for hue in hue_rotations: hsv = np.copy(hsv0) hsv[:,:,0] = hsv[:,:,0]+ hue rgb = color.hsv2rgb(hsv) images[hue] = rgb
Any greyscaled image should be ok but the image used here is:
<https://lh5.googleusercontent.com/-whwEGZWWhIE/UylgLDhf0VI/AAAAAAAABsc/02kl9...>

I agree, this is a nice example. If you want to color many different objects though, I would suggest taking a look at `skimage.color.label2rgb`. I just submitted a PR for some simple artificial tinting: https://github.com/scikit-image/scikit-image/pull/963 On Thu, Mar 20, 2014 at 11:45 AM, Adam Hughes <hughesadam87@gmail.com>wrote:
This would make a nice example IMO, at least an ipython notebook if not something on the gallery page. It's simple, and I've seen other examples on stack overflow with people struggling to get the transformations down in HSV space.
On Thursday, March 20, 2014 10:48:22 AM UTC-4, Jean-Patrick Pommier wrote:
<https://lh3.googleusercontent.com/-XZbiua42-VA/Uyr_pGIEHqI/AAAAAAAABtU/rTheR...> The different spectral components can be combined into one rgb image<http://nbviewer.ipython.org/gist/jeanpat/9665267>to yield:
Le jeudi 20 mars 2014 09:00:48 UTC+1, Jean-Patrick Pommier a écrit :
<https://lh5.googleusercontent.com/-tYhHDFsj2cM/UyqfVvwM_nI/AAAAAAAABtE/wGITF...> Now it's clear for me, thank you for your code!
jp
Le mercredi 19 mars 2014 10:16:45 UTC+1, Jean-Patrick Pommier a écrit :
Hi, I 'd like to modify continuously a pure red image to get an orange, yellow, green, light blue, blue, purple image. The idea is to convert a rgb image, to convert it into hsv color space, to modify the hue value then to back convert into rgb color space. The problem is that only green and blue can be obtained but no intermediate color:
<https://lh4.googleusercontent.com/-s_Acsx0EmRY/UylefCuSGnI/AAAAAAAABsQ/T7pAI...>
According to adobe<http://dba.med.sc.edu/price/irf/Adobe_tg/models/hsb.html>, adding a hue equal to 36 should yield a yellow image.
*Here's the code:*
from skimage import io from skimage import color from scipy import ndimage as nd import numpy as np from matplotlib import pyplot as plt import os
cy55 = io.imread('/home/jeanpat/MFISH/PSI/P07/01/Cy5/P070109C.tif')
zero = np.zeros(cy55.shape,dtype=np.uint8) rgb0 = np.dstack([cy55, zero,zero])
hue_rotations = [18, 36,72,90,108] images = {} images[0] = rgb0 hsv0 = color.rgb2hsv(rgb0) for hue in hue_rotations: hsv = np.copy(hsv0) hsv[:,:,0] = hsv[:,:,0]+ hue rgb = color.hsv2rgb(hsv) images[hue] = rgb
Any greyscaled image should be ok but the image used here is:
<https://lh5.googleusercontent.com/-whwEGZWWhIE/UylgLDhf0VI/AAAAAAAABsc/02kl9...>
--
You received this message because you are subscribed to the Google Groups "scikit-image" group. To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
participants (3)
-
Adam Hughes
-
Jean-Patrick Pommier
-
Tony Yu