Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot images at their native resolution, without any resizing #40

Merged
merged 1 commit into from
May 2, 2016

Conversation

alexdu
Copy link
Contributor

@alexdu alexdu commented Apr 29, 2016

Reason: when you are working with images, you usually want to see the result exactly as you have computed it, not resized or otherwise messed up with.

With this, whatever you want to display using imshow will appear in the notebook at the same resolution as the original image, without any resizing.

Image data is scaled, so the display range parameter works as expected. It's always saved as 8-bit, to keep things simple (didn't see any reason not to).

Limitations:

  • huge images are not downsized, so they will slow down (and maybe lock up) the browser
  • colormaps, axes, other annotations will not work, so you may want to make this optional
  • I doubt SVG will work (not tested), but I'm not sure what to do about it

Test notebook here.

Another example notebook here (I wrote this patch while doing that experiment => now you can see a possible use case for this feature)

That's it.

@blink1073
Copy link
Contributor

Hi @alexdu, there is no way to differentiate between an image produced by imshow and any other plotting command. I think the correct thing to do is to only use the resolution parameter, and default to 150 (the same as Octave).

@alexdu
Copy link
Contributor Author

alexdu commented May 2, 2016

I used the "cdata" property to differentiate between them. Regular plots don't have it, so the "try" block will fail.

See also my test files - both of them have both kinds of plots.

I'm not sure how to use the resolution parameter - should I compute it manually for every single image size I'm going to use? I want to be sure the output matches 1:1 (pixel-perfect alignment) the image I'm going to display. Can you provide an example?

@blink1073
Copy link
Contributor

Thanks! I didn't pick up on your trick there. What happens for you if we just use print and do not specify resolution at all? We could only set the parameter if explicitly overridden.

@alexdu
Copy link
Contributor Author

alexdu commented May 2, 2016

I updated to current version, which removed my changes:
sudo pip install octave_kernel --upgrade --force-reinstall

Then I modified the "print" line to read:
print(_handle, [_filename, '.%(fmt)s']);

and I re-executed the test notebook. Result.

Note: after upgrading, but before changing the line, the result looked exactly the same.

BTW, when printing a figure that contains an image, octave also displays the axis (so the image has some border) and always scales the image to figure size. I want a way to disable the scaling completely.

Side note: you can look at the color test image in the test notebook: the one printed with default options contains some artifacts around the eyes. Are these artifacts a result of the processing you did in octave, or are they introduced by the resizing process used when displaying the result? How can you tell? Look at the same image printed without any resizing (from PR description), and you'll know exactly what you are looking at.

@blink1073
Copy link
Contributor

Okay, I'm sold on this as-is. Thanks, @alexdu!

@blink1073 blink1073 merged commit f4e3689 into Calysto:master May 2, 2016
@blink1073
Copy link
Contributor

Released as 0.16.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants