Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

imwrite flips axis xy image...

83 views
Skip to first unread message

jay vaughan

unread,
May 12, 2008, 7:24:41 PM5/12/08
to
Is there a trick to getting imwrite to not flip images?

I displayed an image in xy mode [with the lower left corner
being the element (1,1)]. Then I used imwrite to save the
data, but it comes out in ij format, flipped vertically.

Is this just one of those MATLAB quirks? Should I just flip
the image ahead of time, or is there a smarter way?
(Plotting with axes 'ij' bothers me even more!)

frame(:,:,1) = flipud(frame(:,:,1));
frame(:,:,2) = flipud(frame(:,:,2));
frame(:,:,3) = flipud(frame(:,:,3));
imwrite(frame,'name.bmp');

Thanks,
J

jay vaughan

unread,
May 12, 2008, 7:24:42 PM5/12/08
to

jay vaughan

unread,
May 12, 2008, 7:24:47 PM5/12/08
to

Steve Eddins

unread,
May 13, 2008, 9:14:10 AM5/13/08
to
jay vaughan wrote:
> Is there a trick to getting imwrite to not flip images?
>
> I displayed an image in xy mode [with the lower left corner
> being the element (1,1)]. Then I used imwrite to save the
> data, but it comes out in ij format, flipped vertically.

imwrite is following the MATLAB convention to display images so that the
first row of the matrix is the top row of image pixels. There's no
option for changing this behavior.

> Is this just one of those MATLAB quirks?

I don't know why you call it a quirk. I believe this convention is MUCH
more common in both image processing and computer graphics than the
other way around.

> Should I just flip
> the image ahead of time, or is there a smarter way?
> (Plotting with axes 'ij' bothers me even more!)
>
> frame(:,:,1) = flipud(frame(:,:,1));
> frame(:,:,2) = flipud(frame(:,:,2));
> frame(:,:,3) = flipud(frame(:,:,3));
> imwrite(frame,'name.bmp');

Coding suggestion:

frame = flipdim(frame, 1);

Long-term suggestion: Make peace with the MATLAB convention. It will
save you repeated headaches.

---
Steve Eddins
http://blogs.mathworks.com/steve/

ImageAnalyst

unread,
May 13, 2008, 10:10:07 AM5/13/08
to

------------------------------------------------
J:
I'm just seconding Steve's opinion. It's very standard in the image
processing field that line 1 is the top line, just like it is for
regular (non image) matrices. MATLAB does have its quirks but this
isn't one of them. In fact it's more of a quirk when you run across
situations or programs where they use Cartesian coordinates to display
images with the origin being at the lower left - that's fairly rare,
non-standard, and quirky. I also suggest that you learn to get used
to it.

The thing I always have to keep an eye out for is the "x,y" and
"row,column" issue. Some functions want arguments of x,y so you have
to pass them in as column,row (because x is the column and y is the
row) instead of the row,column order like you're used to for many or
most other situations. Likewise, if the function or array wants it in
the order "row,column", you have to reverse your x,y and pass in y,x.
Mess this us and you'll get transposed images or plots. Keeps me on
my toes!
Regards,
ImageAnalyst

Steve Eddins

unread,
May 13, 2008, 10:39:53 AM5/13/08
to
ImageAnalyst wrote:
> [snip]

> MATLAB does have its quirks but this isn't one of them.

Agreed! :-)

0 new messages