On Fri, Oct 3, 2014 at 6:22 PM, Tim Holy <[email protected]> wrote:
>
> Where the problems come in is if your code was exploiting some aspect of the
> raw representation of images. In such cases, there is no way to achieve co-
> existence: the image either uses one representation or another, not both. So
> unfortunately it's not possible for me to maintain compatibility the way you
> seem to be asking for. In general, where possible I recommend trying to use
> the API in Images rather than digging into the internal representation---
> that's your best protection against changes.
>

Yes, I had to interface with some older Python and C code, so I
converted the Image to Array using

             convert(Array,img)

which used to give me an Uint8 array n x m x 3 (for colour images)
that I could for example directly pass to the Python routine using
pycall.

In the new version of Images, this command returns a 2D Array of a new
type, UfixedBase{Uint8,8}.
The README suggests to use "separate" to get the Matlab color-last
representation, but the element type remains different than before.
Here, the README did not offer much help. I finally came up with

             convert(Array,uint8(integer(255*separate(img))))

or better

              reinterpret(Uint8,convert(Array,separate(img)))

which seems to work.

My second problem was that I tried to get the color dimension by
"size(img,colordim(img))", in order to process each colour channel
separately. This is actually taken from the documentation
(https://github.com/timholy/Images.jl/blob/master/doc/core.md) but it
no longer works, as "colordim(img)" returns 0. So what is the
recommended way of finding out, whether the image is a color image or
not? Could you update the example in core.md, to show what is the
generic way of processing the color channels one by one?
What I did for the moment was to convert it to Array as above and
counting the number of dimensions but that is obviously not a robust
solution.

This seems to have solved my most problems, although more keep
creeping up as I test some less-often used parts of the code because I
made assumption about the image element type. (I am looking forward to
Julia being able to perform strong typechecking at compile time, this
would find the errors very quickly.) I find it surprisingly difficult
to write a truly generic and type-stable code, especially if it uses
legacy libraries.

Yours,

Jan



-- 
---------------------------------------------------------------------------------------------
Jan Kybic <[email protected]>                    tel. +420 2 2435 5721
http://cmp.felk.cvut.cz/~kybic                      ICQ 200569450

Reply via email to