bugGNU Octave - Bugs: bug #30509, 'imshow' doesn't reverse 'ydir' of...

 
 

bug #30509: 'imshow' doesn't reverse 'ydir' of axis

Submitter:  Søren Hauberg <hauberg>
Submitted:  Wed 21 Jul 2010 12:34:34 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 26 Jul 2010 05:28:52 AM UTC, comment #7: 
Rik <rik5>
Group administrator
Fri 23 Jul 2010 10:30:03 PM UTC, comment #6: 

Thanks for testing testing this on Matlab.  I see that they went for option (1) which is certainly the easiest to implement.  The proposal for Octave then is:

A) set 'ydir' to 'reverse' when using imshow
B) ignore 'hold on' when using imshow and always reverse axes
C) add some documentation on what imshow is doing since it isn't intuitive.

Rik <rik5>
Group administrator
Fri 23 Jul 2010 07:54:58 AM UTC, comment #5: 

I think your interpretation of "doing the right thing" is misguided. Matlab reverses the 'ydir' on images for a very good reason.

If you work on image processing you often have a work-flow where some you have an algorithm that detects certain points in an image (like the eyes in a face). Since we represent images as matrices, these detected points are represented as (row, column). Now, if you show an image and then want to plot the detected points on top of the image (for verification purposes), you simply do this

  imshow (im)
  hold on
  plot (column, row, '*')
  hold off

You can do this because the 'ydir' is reversed. Had that not been the case, you would have to do something like

  imshow (im)
  hold on
  plot (column, size (im, 1) - row, '*')
  hold off

or something like that. This would be a terrible working process.

My point is just that 'ydir' is reversed on purpose.

Now to answer your questions:

1) The line goes from upper left to lower right as it should.

2) Your commands return

>> children = get(gcf, 'children')


children =

  173.0011

>> get (children, 'type')


ans =

axes

3) The command doesn't work

>> handles = get(gca);
>> get(handles, 'ydata')

??? Error using ==> get
Conversion to double from struct is not possible.

I don't know how to test what you wanted to test so I cannot do that. Sorry :-(

Søren Hauberg <hauberg>
Fri 23 Jul 2010 12:44:46 AM UTC, comment #4: 

I think we're getting closer to understanding, and hence finding a solution.

Currently, this sequence doesn't work with Matlab
plot;
hold on
imshow

When you do the reverse
imshow('arrow_up.jpg');
hold on;
plot(1:100,'c');

does Matlab
1) produce the line correctly from the lower left to the upper right?  With 'ydir' reversed I believe the line will also be incorrectly reversed and travels from the upper left to lower right.

2) Assuming Matlab correctly plots part (1), does it do so by creating two axes for the current plot?
children = get(gcf, "children");
get(children, "type")

which might return
ans =

{
  [1,1] = axes
  [2,1] = axes
}

3) If there is only one axis in part (2), and ydir is reversed, has Matlab reversed the ydata manually?

handles = get(gca);
get(handles, 'ydata')

which I would expect to be 100:-1:1.

Rik <rik5>
Group administrator
Thu 22 Jul 2010 06:50:48 AM UTC, comment #3: 

I get the following output:

>> plot(1:100,'c');
>> hold on;
>> get (gca, 'ydir')


ans =

normal

>> imshow ('arrow_up.jpg')

Warning: The image file directory at offset position 38 has zero entries and
has been ignored.

>> get (gca, 'ydir')


ans =

reverse

The figure shows the image (arrow pointing up), but not the plot. Basically, when you show an image the figure is reset. So, when you want a figure containing both an image and a plot you need to show the image first and then make the plot.

Søren Hauberg <hauberg>
Wed 21 Jul 2010 11:46:31 PM UTC, comment #2: 

The 'ydir' property was specifically changed so that images and plots could be overlaid using 'hold on'. 

The original bug report for that (#30033) has more information.

It would be interesting to see how Matlab handles these issues.  If you have access to Matlab could you try the following:

plot(1:100,'c');
hold on;
get (gca, 'ydir')
imshow ("arrow_up.jpg");
get (gca, 'ydir')

What this should show is a cyan line from the lower left to the upper right and the image of an arrow pointing to the top of the screen.  The file "arrow_up.jpg" is attached to the bug report.


Rik <rik5>
Group administrator
Wed 21 Jul 2010 02:08:21 PM UTC, comment #1: 

It looks like the ydir property was set in a compatible way until this changeset:

http://hg.savannah.gnu.org/hgweb/octave/rev/0bcd17cad9d1

which also references this bug report:

https://savannah.gnu.org/bugs/?30033

John W. Eaton <jwe>
Group administrator
Wed 21 Jul 2010 12:34:34 PM UTC, original submission:  

If I do

  imshow (rand (100))
  get (gca, 'ydir')

in a recent checkout I get

  ans = normal

Matlab, on the other hand, gives

  ans = reverse

This screws up plotting on top of images.

Søren Hauberg <hauberg>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #21031:  arrow_up.jpg added by rik5 (4KiB - image/jpeg)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by jwe
  • -email is unavailable- added by hauberg (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2010-07-26 rik5 StatusNeed Info Fixed
        Open/ClosedOpen Closed
    2010-07-21 rik5 Attached File- Added arrow_up.jpg, #21031
        StatusNone Need Info
    2010-07-21 jwe Carbon-Copy- Added rik5

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code