From: Rise on
Hi, all,

Am a newbie to Matlab and image processing. Have been reading the book, Digital Image Processing by Gonzales et al. But I have a question....if someone could explain in more detail to me...

Why do the dimensions of the image change? Is it due to the conversion? e.g.,

I = imread('new-001.tif'); % dimensions for I: width: 1246, height: 912, uint8
I = im2double(rgb2gray(I)); % Now width = 1249, height = 914, double

I am inquiring, because I would like to map the grayscale image, I, to another color image, J, of the same dimensions of I -- when 'I' was originally read in. But I would like to know why the dimensions of I changed in the first place. I am assuming it has something to do with the conversion.

If you know of a link that I could read, please let me know.

Thanks in advance. Sincerely, Rise
From: Steve Eddins on
On 7/8/2010 11:42 AM, Rise wrote:
> Hi, all,
> Am a newbie to Matlab and image processing. Have been reading the book,
> Digital Image Processing by Gonzales et al. But I have a question....if
> someone could explain in more detail to me...
>
> Why do the dimensions of the image change? Is it due to the conversion?
> e.g.,
> I = imread('new-001.tif'); % dimensions for I: width: 1246, height: 912,
> uint8
> I = im2double(rgb2gray(I)); % Now width = 1249, height = 914, double
>
> I am inquiring, because I would like to map the grayscale image, I, to
> another color image, J, of the same dimensions of I -- when 'I' was
> originally read in. But I would like to know why the dimensions of I
> changed in the first place. I am assuming it has something to do with
> the conversion.
>
> If you know of a link that I could read, please let me know.
> Thanks in advance. Sincerely, Rise

Neither rgb2gray nor im2double should change the image size in this way.

Possible explanations:

* The image in the TIFF file is really 1249x914 instead of 1246x912.
What is the output for:

imfinfo('new-001.tif')
size(imread('new-001.tif'))

* You have modified versions of the functions im2double or rgb2gray on
your path. What is the output for:

which -all im2double
which -all rgb2gray

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

From: Rise on
Hi, Steve,

Here is the information that I get. Thnx for your assistance. - Rise

>> imfinfo('new-002.tif')
ans =
Filename: 'new-002.tif'
FileModDate: '03-May-2010 14:05:46'
FileSize: 2898754
Format: 'tif'
FormatVersion: []
Width: 1247
Height: 912
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: [73 73 42 0]
ByteOrder: 'little-endian'
NewSubFileType: 0
BitsPerSample: [8 8 8]
Compression: 'PackBits'
PhotometricInterpretation: 'RGB'
StripOffsets: [456x1 double]
SamplesPerPixel: 3
RowsPerStrip: 2
StripByteCounts: [456x1 double]
XResolution: 72
YResolution: 72
ResolutionUnit: 'Inch'
Colormap: []
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: [255 255 255]
MinSampleValue: 0
Thresholding: 1
Offset: 2894910
>> size(imread('new-002.tif'))
ans =
912 1247 3
>> which -all im2double
C:\Program Files\MATLAB\R2010a\toolbox\images\images\im2double.m
>> which -all rgb2gray
C:\Program Files\MATLAB\R2010a\toolbox\images\images\rgb2gray.m
>>
From: Rise on
Hi, Steve,

I am looking at my code, and see where the dimensions are changing. I have the following:

[I, map] = imread('new-002.tif');
I = im2double(rgb2gray(I));
gx = conv2(I,h); % extract horizontal edges of I
gy = conv2(I,v); % extract vertical edges of I
gm = sqrt(gx.*gx + gy.*gy); % magnitude

It is here that my image apparently changes from
>> size(imread('new-002.tif'))
ans =
912 1247 3

to this:
>> size(gm)
ans =
914 1249
>>

Hm. But I still don't understand why the dimensions are changing if I am using the gradient. Thnx in advance for your explanation. Sincerely, Rise
From: Rise on
Hi, Steve,

Here is more information re. conv2 and sqrt:

>> which -all sqrt
built-in (C:\Program Files\MATLAB\R2010a\toolbox\matlab\elfun\@double\sqrt) % double method
built-in (C:\Program Files\MATLAB\R2010a\toolbox\matlab\elfun\@single\sqrt) % single method
C:\Program Files\MATLAB\R2010a\toolbox\distcomp\parallel\@codistributed\sqrt.m % codistributed method
>> which -all conv2
built-in (C:\Program Files\MATLAB\R2010a\toolbox\matlab\datafun\@single\conv2) % single method
built-in (C:\Program Files\MATLAB\R2010a\toolbox\matlab\datafun\@double\conv2) % double method
C:\Program Files\MATLAB\R2010a\toolbox\matlab\datafun\@uint8\conv2.m % uint8 method
C:\Program Files\MATLAB\R2010a\toolbox\matlab\datafun\@uint16\conv2.m % uint16 method
>>