PerceptualColourMaps.jl icon indicating copy to clipboard operation
PerceptualColourMaps.jl copied to clipboard

Data output format from applycolormap seems to have wrong dimensions

Open lwabeke opened this issue 7 years ago • 3 comments

Hi

I'm trying to do something similar to below:

using Images, PerceptualColourMaps

dataIn = sineramp()
tmp = applycolormap(dataIn, cmap("R3"))
@show typeof(tmp), size(tmp)
img = colorview(RGB, permutedims(tmp, (3,1,2)))
save("tester.png",  img)

It seems applycolormap is outputting data in MxNx3 format, while colorview and the rest of the Images.jl package needs it in 3xMxN format. Am I missing something? Or is there a way to apply the colormap to directly get the 3xMxN format without needing the interim permutedims step?

I'm willing to help work an a PR if needed, just don't want to do something if it is already catered for in another manner. I'm guessing other uses of applycolormap needs it in the correct output format and just changing format as a breaking change is not prefered.

Thanks

lwabeke avatar Sep 07 '17 08:09 lwabeke

Thanks for raising this. I confess I tend to use PyPlot for image display and I have not been keeping up with the latest in the Images package. The 3xMxN format in Images makes a lot of sense but the MxNx3 convention is pretty much universal elsewhere, eg. PyPlot. If you are willing to work on a PR that would be great. Perhaps the simplest approach might be to have an extra optional argument to applycolourmap() that allows you to specify the desired format of the output image. However I am open to other ideas

Cheers

peterkovesi avatar Sep 10 '17 13:09 peterkovesi

I was thinking of something similar, just wasn't sure if there was something already that I had just missed.

Something like a call: img = applycolormap(dataIn, cmap("R3"), RGB) I also like what they have in terms of Gray: img = Gray.(dataIn)

thus maybe img = cmap("R3").(dataIn)

However I would need to go look if that is even possible, due to how the dimensions change together with the loop fusion. Guess that a RGB should potentially still actually be in there somewhere.

I'll play around and see what I can come up with.

lwabeke avatar Sep 11 '17 07:09 lwabeke

I found the get function in ColorSchemes.jl, by just making sure it can run over an array, it seems to work for both their ColorSchemes and the PerceptualColourMaps, see:

https://github.com/JuliaGraphics/ColorSchemes.jl/pull/9

I further extended it to give similar control over the end values.

Once that is merged, maybe a mod to applycolourmap to add a see also ColorSchemes.get

lwabeke avatar Sep 13 '17 09:09 lwabeke