-
Notifications
You must be signed in to change notification settings - Fork 139
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
Image x, y coordinate of pixel from which spectrum was displayed? #115
Comments
Current mouse position (in pixel coordinates) are displayed in the bottom margin of the Matplotlib display, though that may not happen if you are displaying in a jupyter notebook. So the easiest (i.e., do nothing) way to get the coordinates is to note the coordinate being displayed in the window. If you want to do a little hacking, you can override the callback that handles spectrum plotting. By default, the plot is created by the ImageViewMouseHandler. You can create a subclass that overrides the
Note that the only new line above is the "YOU CLICKED" line. To use the new callback in an image display, do something like this:
Then, whenever you double-click in the display, you'll see output like this:
Obviously, you can change the handler however you like. So you could, for example, add a legend to the plot that displays the coordinates of the pixel or add them to a list in your mouse handler to save for subsequent processing. |
WOW! Thank you so much. All I want is the quick display of clicked pixel coords, and I didn't see that in the WX-based window generated by imshow. I'll recheck it to see if I missed it. Then I'll try your solution above. |
I found that the pixel coords are displayed at lower right in the WX-based new window, but are mostly obscured. See image. I guess the issue is related to the wxpython and perhaps pyopengl, both of which I had to install to get the WX backend working from a notebook. Setting figsize in imshow doesn't help. Any ideas? The pixel coords display normally in my notebook if a %matplotlib widget (ipympl) is used for interactive display, but then I can't double-click to get the spectral plot! I also tried your function above, but don't understand how I define "MyMouseHandler" to read the new function. After adding your function as you wrote, I tried this:
Could you please show how to define MyMouseHandler? |
Oops. I forgot to include the first line of the class definition in my code example. I just edited it. Take another look. |
Hmm, I see no change. I used this code after invoking the imshow to the view variable:
Is that correct? Since the pixel coords are mainly blocked from view at the lower right corner of window, will the "YOU CLICKED (78, 110)" even be visible? My wx backend could be the problem. I just installed wxwidgets, but that hasn't helped the obscured text issue. |
I must have forgotten to click the update button. Check again now. Basically, I forgot this line:
|
It worked!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! YOU CLICKED line displayed in notebook!!!!!!!!!!!! Perfect. Great job. Many thanks. |
Here is sample code to extract spectra from cube using Jupyter Notebook and new mouse handler from above:
|
I am not able to select a pixel , |
@SondosBsharat I need more info to help you. Try this before calling
If there are no exceptions generated, close the window, run the following command, then provide any output given after you double-click in the image:
|
Hello, is there a way to display the x/y coordinates of a pixel from which a spectrum was just displayed using imshow? When I double-click on a displayed image and a pixel spectrum is displayed in a new pop-up window, it would be great if the x/y coord was displayed so that I could then easily extract that spectrum from the cube using
spectrum1 = image.read_pixel(2225, 3801)
Now I have to use ENVI to get the pixel coordinate, or display the image in the normal backend using %matplotlib widget magic, with which x/y coords and band DN values are streamed when you move the mouse.
Thank you...
The text was updated successfully, but these errors were encountered: