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

 
 

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

Submitted by:  Søren Hauberg <hauberg>
Submitted on:  Wed 21 Jul 2010 12:34:34 PM UTC  
 
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: None
Status: FixedAssigned to: None
Originator Name: Open/Closed: Closed
Release: devOperating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Mon 26 Jul 2010 05:28:52 AM UTC, comment #7:

Fixed in the following changeset:
http://hg.savannah.gnu.org/hgweb/octave/rev/d9147775da54

Rik <rik5>
Project 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>
Project 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>
Project 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.

(file #21031)

Rik <rik5>
Project 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>
Project 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 File(s):
   
   
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
  • -unavailable- added by rik5 (Updated the item)
  • -unavailable- added by jwe (Posted a comment)
  • -unavailable- added by jwe
  • -unavailable- added by hauberg (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 5 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 26 Jul 2010 05:28:52 AM UTCrik5StatusNeed Info=>Fixed
      Open/ClosedOpen=>Closed
    Wed 21 Jul 2010 11:46:31 PM UTCrik5Attached File-=>Added arrow_up.jpg, #21031
      StatusNone=>Need Info
    Wed 21 Jul 2010 02:08:21 PM UTCjweCarbon-Copy-=>Added rik5

    Back to the top


    Powered by Savane 3.1-cleanup1