Re : Re: multispectral imaging: rgb image

jip jeanpatrick.pommier at gmail.com
Fri May 20 15:46:53 EDT 2011


Hi Stéfan,
The following script try to produce a rgb image from a five channels image 
(with the grey images from my blog<http://dip4fish.blogspot.com/2011/05/mfish-image-to-rgb-with-image5d.html>, 
converted to png:FarRed, Red, Gold, Green, Aqua(blue)). It fails with error:

red=c3_r.reshape(c3,shape)
TypeError: only length-1 arrays can be converted to Python scalars

The other issue is how to choose the coef of the matrix m such that the 
colors are "well separated". In the HSV space<http://en.wikipedia.org/wiki/HSL_and_HSV>, 
I suppose it is possible to choose the coef such that the colors are 
separated by 2pi/5 in the hue component,starting with FarRed=0°.

*import numpy as np
import readmagick
import os
user=os.path.expanduser("~")
workdir=os.path.join(user,"Applications","ImagesTest","MFISH")
blue="Aqua.tif"
green="Green.tif"
gold="Gold.tif"
red="Red.tif"
frd="FarRed.tif"
complete_path=os.path.join(workdir,blue)
i1=readmagick.readimg(complete_path)
#
complete_path=os.path.join(workdir,green)
i2=readmagick.readimg(complete_path)
#
complete_path=os.path.join(workdir,gold)
i3=readmagick.readimg(complete_path)
#
complete_path=os.path.join(workdir,red)
i4=readmagick.readimg(complete_path)
#
complete_path=os.path.join(workdir,frd)
i5=readmagick.readimg(complete_path)
#
shape=i5.shape
print shape
b=i1.flatten()
g=i2.flatten()
y=i3.flatten()
r=i4.flatten()
f=i5.flatten()
#make a 2D array
#each line is a pixel, column=channel
channel5=np.vstack((f,r,y,g,b))
c5=channel5.T
print c5.shape
#try some coef
m=np.array([[0.0, 0.02, 0.80],
            [0.0, 0.03, 0.10],
            [0.10, 0.05, 0.05],
            [0.10, 0.80, 0.04],
            [0.80, 0.10, 0.01]])
print m.shape

#produce  a flat rgb image
c3=np.dot(c5,m)
print "c3:",c3.shape
c3_r=c3[:,0]
print "c3_r:",c3_r.shape,c3_r.dtype
c3_g=c3[:,1]
c3_b=c3[:,2]
print c3_r.shape
red=c3_r.reshape(c3,shape)#should be a red image
green=c3_g.reshape(c3,shape)
blue=c3_b.reshape(c3,shape)
import pylab
pylab.imshow(red)
pylab.show*


Best regards
Jean-Patrick

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20110520/55d60e95/attachment.html>


More information about the scikit-image mailing list