Hi Tony,

On Sat, Oct 31, 2009 at 5:36 PM, Tony S Yu <tsyu80@gmail.com> wrote:
Hi Ralf, 

Thanks for the feedback.

On Oct 30, 2009, at 11:31 AM, Ralf Gommers wrote:
The images on the page you linked to can not be included I think (copyright), so could you generate two small palette images (one rgb, one grey, 10x10 pixels) for use in a test? (or ideally, write the test:))

I couldn't easily find any palette images that weren't copyrighted; it never occurred to me just create them. Thanks.

You're welcome. In addition to avoiding copyright issues, it is nice to have very small images. Otherwise the size of the scikit would be completely dominated by lots of large test images after a while.

Also, I see you are already using git, so next time could you push your changes to github as described here http://stefanv.github.com/scikits.image/contribute.html#development-process, that would make it a bit faster to test.

I was afraid I'd have to learn git. ;)

I trust it wasn't too painful, thanks for doing it.
 
I added the changes in three commits to: http://github.com/tonysyu/scikits.image
The first commit just adds the images, the second adds palette image handling + a test, and the third adds an additional test.

I wasn't sure how to test imread. I ended up checking that imread returns a 2D array for the grayscale palette image and a 3D array for the color palette image. Another possibility is to test the values of the array, but that seems fragile.

This looks fine to me. Testing values would be good as well, and if you do it with assert_array_almost_equal from numpy.testing it should not be fragile.
 
The last commit adds a test of the function `palette_is_gray`. Unfortunately, the test is a bit ugly. First, I had to add an import of PIL in the test, since palette_is_gray works specifically on PIL palette images. Second, I had to add `palette_is_grayscale` to __all__ in pil_imread so that I could use the function in my test. (Python documentation suggests that __all__ only affects ``from <> import *``, but it seemed to prevent ``from scikits.image.io import palette_is_grayscale``.)

The PIL import is fine, but the try-except block is unnecessary since that is already done in imread.

Adding to __all__ is not necessary, you can import it from io.pil_imread.

I did notice that other imread tests fail already if PIL is not available. For this we do need an @pil_skip decorator I think.
 
Let me know what you think of the tests. Also, should I do a pull request?

Looks good overall. I made some minor changes reflecting the comments I made above: http://github.com/rgommers/scikits.image/commit/a6ad7415d7a43185cea898d3454e087b0b01f105

If you are happy with those, you can pull my palette branch over and send Stefan a pull request.

Cheers,
Ralf