Page 1 of 1

How to get the dimensions of an image?!

Posted: 2008-07-02T10:07:32-07:00
by jstoezel
Hello,

I would like to get the dimensions of an image (horizontal and vertical pixels). This is what I though would work:

m_Image.read(fileName);
ImageSize_x = m_Image.rows();
ImageSize_y = m_Image.columns();

However, m_Image.rows() always returns a huge number, while m_Image.columns() always returns 0.

Any idea!?

Thanks!

Re: How to get the dimensions of an image?!

Posted: 2008-07-02T10:46:20-07:00
by koopa
Looks right to me, so a fair question. Can we get an fuller example, maybe in the form:

m_Image.read("test.png"); // Portable Network Graphic (non-interlaced)
long ImageSize_x = m_Image.rows(); // should be 300
long ImageSize_y = m_Image.columns(); // should be 200

Is this for every image, or just some?

Shouldn't columns be x (or maybe more clearly width)?

-Chris

Re: How to get the dimensions of an image?!

Posted: 2008-07-02T10:50:05-07:00
by jstoezel
koopa wrote:Looks right to me, so a fair question. Can we get an fuller example, maybe in the form:

m_Image.read("test.png"); // Portable Network Graphic (non-interlaced)
long ImageSize_x = m_Image.rows(); // should be 300
long ImageSize_y = m_Image.columns(); // should be 200

Is this for every image, or just some?

Shouldn't columns be x (or maybe more clearly width)?

-Chris
Hi,

I got it to work by using the geometry function:

m_Image.read(fileName);
Geometry mygeo;
mygeo = m_Image.size();
ImageSize_y = mygeo.height();
ImageSize_x = mygeo.width();

I used the exact same image I used with the previous example.

Re: How to get the dimensions of an image?!

Posted: 2008-07-02T11:15:58-07:00
by koopa
If it works more power to you, but I still feel uneasy about it. Unfortunately I don't have any answers to offer.

-Chris