Higher Resolution Palettes for Images

Hello everyone,

I have some trouble with greyscale plotting. The data for the plot shown in this example is a 256x256 greyscale 2d-numpy-array with 16bit resolution.

1.) I would like to to make the plot look like the right picture with higher greyscale resolution. How can I achieve that?
2) Within the “figure” function I can define the size of the plot, but actually it is not the size of the plot but the size of the canvas element.
I would like to have the image-area itself with 256x256 without the white borders around them. Is there a setting to disable the border?

The code:

import numpy as np
from bokeh.plotting import figure, show, output_file

size = 256

image = open("rawpicdata", "rb")
array = np.fromfile(image, dtype=np.uint16)
img_array = array.reshape(size, size)

output_file("greyscale.html", title="Greyscale_Image")

p = figure(x_range=[0,size], y_range=[0,size], plot_width=size, plot_height=size)

p.image(image=[img_array[::-1]], x=[0], y=[0], dw=[size], dh=[size])
p.xaxis.visible = False
p.yaxis.visible = False
show(p)

Thank you
kju

Hey,

Regarding your second point, try adding “p.min_border = 0”. Note that there still seems to be a 1px border drawn over the outer pixels of the data.

Regards,
Rutger

···

On Saturday, August 1, 2015 at 5:36:28 AM UTC+2, kju factor wrote:

Hello everyone,

I have some trouble with greyscale plotting. The data for the plot shown in this example is a 256x256 greyscale 2d-numpy-array with 16bit resolution.

1.) I would like to to make the plot look like the right picture with higher greyscale resolution. How can I achieve that?
2) Within the “figure” function I can define the size of the plot, but actually it is not the size of the plot but the size of the canvas element.
I would like to have the image-area itself with 256x256 without the white borders around them. Is there a setting to disable the border?

The code:

import numpy as np
from bokeh.plotting import figure, show, output_file

size = 256

image = open("rawpicdata", "rb")
array = np.fromfile(image, dtype=np.uint16)
img_array = array.reshape(size, size)

output_file("greyscale.html", title="Greyscale_Image")

p = figure(x_range=[0,size], y_range=[0,size], plot_width=size, plot_height=size)

p.image(image=[img_array[::-1]], x=[0], y=[0], dw=[size], dh=[size])
p.xaxis.visible = False
p.yaxis.visible = False
show(p)

Thank you
kju

Hi,

I have a solution for the map/colormap. I will post it today evening, when I am back from work.

best regards
kju

···

Am 01.08.2015 05:36 schrieb “kju factor” [email protected]:

Hello everyone,

I have some trouble with greyscale plotting. The data for the plot shown in this example is a 256x256 greyscale 2d-numpy-array with 16bit resolution.

1.) I would like to to make the plot look like the right picture with higher greyscale resolution. How can I achieve that?
2) Within the “figure” function I can define the size of the plot, but actually it is not the size of the plot but the size of the canvas element.
I would like to have the image-area itself with 256x256 without the white borders around them. Is there a setting to disable the border?

The code:

import numpy as np
from bokeh.plotting import figure, show, output_file

size = 256

image = open("rawpicdata", "rb")
array = np.fromfile(image, dtype=np.uint16)
img_array = array.reshape(size, size)

output_file("greyscale.html", title="Greyscale_Image")

p = figure(x_range=[0,size], y_range=[0,size], plot_width=size, plot_height=size)

p.image(image=[img_array[::-1]], x=[0], y=[0], dw=[size], dh=[size])
p.xaxis.visible = False
p.yaxis.visible = False
show(p)

Thank you
kju

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/fbbba7ca-1bce-48f7-b135-289488a7a2ae%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hello,

so here is the solution that worls for me:
I was confused, because the description of the “image” method of the bokeh plotting Interface says the argument has to be colorMapper=“Your-LCM-Object” but actually it has to be color_mapper=“Your-LCM-Object”.

Define your palette …

palette = [’#f30000’, ‘#2a00ff’, ‘#fff117’, ‘#00ff4c’, ‘#ffaf00’]

… and spread it linear over the bitdepth of the greayscale image

lcm = LinearColorMapper()
lcm.low = 0
lcm.high = 65535
lcm.palette = palette
… # same code as in first post

pass the linearized new colormap here via “color_mapper=lcm”

p.image(image=[array[::-1]], x=[0], y=[0], dw=[size], dh=[size], color_mapper=lcm)

removes the border around the picture completely. (No border when saving the image from browser later)

p.min_border = 0

… # same code as in first post

show§

``

regards
kju

···

Am Montag, 3. August 2015 11:55:23 UTC+2 schrieb kju factor:

Hi,

I have a solution for the map/colormap. I will post it today evening, when I am back from work.

best regards
kju

Am 01.08.2015 05:36 schrieb “kju factor” [email protected]:

Hello everyone,

I have some trouble with greyscale plotting. The data for the plot shown in this example is a 256x256 greyscale 2d-numpy-array with 16bit resolution.

1.) I would like to to make the plot look like the right picture with higher greyscale resolution. How can I achieve that?
2) Within the “figure” function I can define the size of the plot, but actually it is not the size of the plot but the size of the canvas element.
I would like to have the image-area itself with 256x256 without the white borders around them. Is there a setting to disable the border?

The code:

import numpy as np
from bokeh.plotting import figure, show, output_file

size = 256

image = open("rawpicdata", "rb")
array = np.fromfile(image, dtype=np.uint16)
img_array = array.reshape(size, size)

output_file("greyscale.html", title="Greyscale_Image")

p = figure(x_range=[0,size], y_range=[0,size], plot_width=size, plot_height=size)

p.image(image=[img_array[::-1]], x=[0], y=[0], dw=[size], dh=[size])
p.xaxis.visible = False
p.yaxis.visible = False
show(p)

Thank you
kju

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/fbbba7ca-1bce-48f7-b135-289488a7a2ae%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi,

This have been addressed here: https://github.com/bokeh/bokeh/pull/2690

Thanks for the report. If you feel so, next time you can also open an issue or propose a PR with a fix.

Cheers

Fabio

···

On Wed, Aug 5, 2015 at 11:40 PM, kju factor [email protected] wrote:

Hello,

so here is the solution that worls for me:
I was confused, because the description of the “image” method of the bokeh plotting Interface says the argument has to be colorMapper=“Your-LCM-Object” but actually it has to be color_mapper=“Your-LCM-Object”.

Define your palette …

palette = [’#f30000’, ‘#2a00ff’, ‘#fff117’, ‘#00ff4c’, ‘#ffaf00’]

… and spread it linear over the bitdepth of the greayscale image

lcm = LinearColorMapper()
lcm.low = 0
lcm.high = 65535
lcm.palette = palette
… # same code as in first post

pass the linearized new colormap here via “color_mapper=lcm”

p.image(image=[array[::-1]], x=[0], y=[0], dw=[size], dh=[size], color_mapper=lcm)

removes the border around the picture completely. (No border when saving the image from browser later)

p.min_border = 0

… # same code as in first post

show§

``

regards
kju

Am Montag, 3. August 2015 11:55:23 UTC+2 schrieb kju factor:

Hi,

I have a solution for the map/colormap. I will post it today evening, when I am back from work.

best regards
kju

Am 01.08.2015 05:36 schrieb “kju factor” [email protected]:

Hello everyone,

I have some trouble with greyscale plotting. The data for the plot shown in this example is a 256x256 greyscale 2d-numpy-array with 16bit resolution.

1.) I would like to to make the plot look like the right picture with higher greyscale resolution. How can I achieve that?
2) Within the “figure” function I can define the size of the plot, but actually it is not the size of the plot but the size of the canvas element.
I would like to have the image-area itself with 256x256 without the white borders around them. Is there a setting to disable the border?

The code:

import numpy as np
from bokeh.plotting import figure, show, output_file

size = 256

image = open("rawpicdata", "rb")
array = np.fromfile(image, dtype=np.uint16)
img_array = array.reshape(size, size)

output_file("greyscale.html", title="Greyscale_Image")

p = figure(x_range=[0,size], y_range=[0,size], plot_width=size, plot_height=size)

p.image(image=[img_array[::-1]], x=[0], y=[0], dw=[size], dh=[size])
p.xaxis.visible = False
p.yaxis.visible = False
show(p)

Thank you
kju

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/fbbba7ca-1bce-48f7-b135-289488a7a2ae%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/3465e098-ffc0-4538-8d7d-fe060828b5d9%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Fabio Pliger

Senior Software Engineer, Bokeh

Hi,

Colormapping is a cool thing and it is easy with the LinearColormapper.
Anyway, I have to map some colors in a non linear way. How can I do that in bokeh?
This example shows how the Linear Color Mapper works internally:


      x < 0  : 'red'     # values < low are clamped
 0 >= x < 33 : 'red'
33 >= x < 66 : 'green'
66 >= x < 99 : 'blue'
99 >= x      : 'blue'    # values > high are clamped

``

Can I somehow specify my own color ranges like so?

greets
kju