question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Flip images when ranges are reversed

See original GitHub issue

Hello,

I’m new to Bokeh, and it might be that I’m using the library wrong, but in most of the image libraries the [0,0] pixel refers to the top left pixel of the image, while in Bokeh (I have not been able to change it) the [0,0] coordinate refers to the bottom left pixel of the image. This simple script to load and plot an image:

import bokeh.plotting as plt
from skimage.io import imread
lenna = imread('/tmp/lenna.png', flatten=True)
p = plt.figure(x_range=[0,10], y_range=[0,10])
p.image(image=[lenna], x=0, y=0, dw=10, dh=10, palette='Greys9')
plt.show(p)

Results with the image plotted upside down, as seen in the attached images (image is also converted to grayscale but this is not relevant):

I’ve tried reversing the range to [10, 0] but this results in displacing the image, not fliping the y axis. The only way I’ve found to plotting it right is by flipping the numpy array lenna[::-1] before sending it to plot (but I guess it should be a better way).

Is there a way of doing it? Is it a bug? Or am I using the library wrong?

Thank you

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
Imperssonatorcommented, Nov 26, 2017

I’m going to +1 this because it’s still an issue in 12.10.

I would propose adding an option invert_y with a default of false, which would ensure backwards compatibility. origin implies translation, not inversion of any axes.

2reactions
markroxorcommented, Oct 5, 2018

Flip the image first using lenna = np.flipud(lenna)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do cameras flip/reverse the photos taken at times? - Quora
The front-facing selfie camera on many phones does in fact create reversed images: It is not an illusion. · This horizontal flipping is...
Read more >
[LeetCode][Python] | 832. Flipping an Image (reverse an array)
To flip an image horizontally means that each row of the image is reversed. For example, flipping [1,1,0] horizontally results in [0,1,1].
Read more >
Flipping an Image in Python - Tutorialspoint
To flip the image horizontally each row of the image will be reversed. And to invert the image each 0 will be replaced...
Read more >
Flipping Scanned Images - The New York Times
Slide images scanned upside-down or in reverse can be corrected with Windows or OS X programs, or with image-editing software.
Read more >
Transformation - Basic Image Manipulation - CodinGame
A flip (mirror effect) is done by reversing the pixels horizontally or vertically. For instance, for an horizontal flip, the pixel situated at...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found