Hello Guy,
lcms supports u8, u16 and f64. Your f32 has to be converted to one of
these. Beside not knowing much about python, not doing so could cause a
error.
kind regards
Kai-Uwe Behrmann
--
developing for colour management
www.behrmann.name + www.oyranos.org
Am 02.07.08, 18:28 +1200 schrieb Guy K. Kloss:
> Hi,
>
> I'm having a bit trouble with the Python bindings of Lcms. I just can't
> figure
> out what type of object to create to pass as an argument 2 to the
> cmsDoTransform(...) function. I want to use floatint point values (0.0 to
> 1.0) for RGB tuples rather than byte values (0 to 255) to convert from sRGB
> to Lab. Of course I could multiply the the floating point value by 255 and
> convert to an int, but that would introduce unnecessary rounding errors if
> performed often.
>
> To highlight the problem I've added a little script. I'm passing in a numpy
> float array for the RGB tuple, and I want to convert that one to Lab (as
> float).
>
> Any input on this? The Python examples in python/testbed were not
> enlightening
> here, and I could only find compatible structures called COLORB and COLORW,
> which seem to be byte and some sort of int respectively, but not float.
>
> I've tried passing in a numpy array, the "data" member of the numpy array, a
> Python list/tuple containing floats, but then all I'm getting is this:
>
> TypeError: in method 'cmsDoTransform', argument 2 of type 'LPVOID'
>
> It's probably simple, once you know, but for now I'm a bit lost ... :-/
>
> Guy
>
>
> import numpy
> from lcms import lcms
>
> XFORM_SRGB2LAB = lcms.cmsCreateTransform(H_SRGB, lcms.TYPE_RGB_DBL,
> H_LAB, lcms.TYPE_Lab_DBL,
> lcms.INTENT_PERCEPTUAL,
> lcms.cmsFLAGS_NOTPRECALC)
>
> def convert_sRGB2Lab(rgbColour):
> """
> Converts sRGB to CIE L*a*b colour tuples. The sRGB colour tuple is tp be
> given as floating point values (0.0 ... 1.0).
> """
>
> # I'm missing some magic here. What structure "colour" do I create
> # here, that I can feed into cmsDoTransform(...) below
> colour = ...
>
> lab = lcms.cmsCIELab()
> lcms.cmsDoTransform(XFORM_SRGB2LAB, colour, lab, 1)
> return numpy.array([lab.L, lab.a, lab.b])
>
>
> if __name__ == '__main__':
> # Patch A01 of che GretagMacbeth ColorChecker
> anRgbColour = numpy.array([116.0 / 255,
> 81.0 / 255,
> 67.0 / 255])
> lab = convert_sRGB2Lab(anRgbColour)
> print lab
>
> --
> Guy K. Kloss
> Institute of Information and Mathematical Sciences
> Te Kura Putaiao o Mohiohio me Pangarau
> Room 2.63, Quad Block A Building
> Massey University, Auckland, Albany
> Private Bag 102 904, North Shore Mail Centre
> voice: +64 9 414-0800 ext. 9585 fax: +64 9 441-8181
> eMail: [EMAIL PROTECTED] http://www.massey.ac.nz/~gkloss/
>
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Lcms-user mailing list
Lcms-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lcms-user