COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

Why do Image Size Dimensions Change

• Email
• Follow

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.


 0

See related articles to this posting

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.
>
> 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')

* 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/


 0
Reply steve.eddins (785) 7/8/2010 5:50:26 PM

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
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
>>

 0

Hi, Steve,

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

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
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

 0

Hi, Steve,

>> 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
>>

 0

Hi, Steve,

>> 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
>>

 0

Dear Rise,

> I am looking at my code, and see where the dimensions are changing. I have the following:
>     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
> 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.

Wow, Rise, this differs in some very important details from your first posting. It is not helpful for the people, who want to help, to omit these information.

You do not post the definition of "h" and "v". Anyhow, what do you expect CONV2 to do? Read the doc of CONV2 to get the answer, why this changes the size.

Kind regards, Jan

 0

Hi, Jan,

So sorry for the omittance and confusion. I didn't know if I should have posted my entire code as is and wanted to keep it simple in presenting my question, but for future posts on this forum, I will indeed post it as is.

My code is using a for loop to read in a sequence of images and then computes the gradient of each image:

thepath = '\\files.med.harvard.edu\home\MATLAB\002\results-0.45-gamma-monkey\';
filelist = dir(fullfile(thepath,'new-*.tif'));
fileNames = {filelist.name}'
nImages = length(fileNames);

% Sobel horizontal and vertical masks
h = fspecial('sobel');
v = h';

% Read in each image, convert to grayscale and double, and find the
% magnitude, magnitude direction and edge direction. We get a vector
% per pixel, with its direction perpendicular to an edge and its
% magnitude proportional to the contrast
for (k = 1:nImages)
I{k} = im2double(rgb2gray(I{k})); %range is [0 1]
gx = conv2(I{k},h); % extract horizontal edges of I
gy = conv2(I{k},v); % extract vertical edges of I
gm = sqrt(gx.*gx + gy.*gy); % combine both horizontal and vertical edges
theta = atan2(gy,gx); %magnitude direction, angles in [-PI, PI] and quadrant accurate
thetaedge = atan2(-gx,gy); %angle/direction of the magnitude

% more code...
end

Yes, I believe that the issue may be when I use conv2 because when read in the size of each image goes from <912x1247> to <914x1249> after I use conv2.

And yes, from what I've read in the Help section on conv2(A,B), "The size of C in each dimension is equal to the sum of the corresponding dimensions of the input matrices, minus one. That is, if the size of A is [ma,na] and the size of B is [mb,nb], then the size of C is [ma+mb-1,na+nb-1]."

Ah, ok, so now I know where the numbers come from so that my image goes from <912x1247> to <914x1249>. I don't completely understand why it is doing this on a deeper level.

Hm. I do see that I can use the following so that my grayscale is the same size as my original read in image. For example, instead of using:

conv2(I{k}, h);

I think I need to use the one below as "same - Returns the central part of the convolution of the same size as A."

conv2(I{k}, h, same);

Yes? Thank you very much in advance. Sincerely, Rise

 0

Dear Rise,

> I think I need to use the one below as "same - Returns the central part of the convolution of the same size as A."
> conv2(I{k}, h, same);

Include the quotes...
conv2(I{k}, h, 'same')

Good luck, Jan

 0

Hi, Jan,

Yes, sigh, I forgot the single quotes. Thanks for being patient with my learning curve and thanks for the luck, as I definitely need it!

Cheers, - Rise ;-)~

 0

9 Replies
264 Views

Similar Articles

12/8/2013 3:49:17 AM
page loaded in 235878 ms. (1)

Similar Artilces:

Ok, how do they do it?
For those who use socks, how the heck do you do it? I admit it - using two names is confusing and I cannot keep track of what I posted with each name. For those who accuse me of using socks, I simply *could* not. Too damned confusing. I would post with the wrong name quite quickly and bust myself. Just insane to keep track of. -- Herd Watch posts are posted by Snit.

do / end do / continue
Hi! do k=1,N I=funktion(k) if (I.le.k) go to 103 ... 100 continue end do It is possible to make this code better/nicer? I tried: do k=1,N I=funktion(k) if (I.le.k) continue ... end do But this hasn't gone. BTW: I am using GFORTRAN (Gnu Fortran 95). Thanks, Flo -- Unofficial Dr-DOS page <http://www.drdos.org> I assume that the problem is with the line: if (I.le.k) continue which is rather like the line: IF ( 1 .GT. 2 ) GO TO 666 as CONTINUE is a dummy statement, and not associated with the end of the DO loop Try replacing the CONTINUE statement with a EXIT statement Hi! Thank you. I have replaced it with "cycle". It works now! Bye, Flo David Flower wrote: > I assume that the problem is with the line: > > if (I.le.k) continue > > which is rather like the line: > > IF ( 1 .GT. 2 ) GO TO 666 > > as CONTINUE is a dummy statement, and not associated with the end of > the DO loop > > Try replacing the CONTINUE statement with a EXIT statement > Florian Xaver wrote: > Hi! > > do k=1,N > I=funktion(k) > if (I.le.k) go to 103 > >

Hos do I do this?
Hi all, I have been struggling in writing a code to do some data processing for the last couple of days. I am pretty new in trying matlab and probably what I am trying to di is going to be pretty easy for most of you folks. Here is what I am trying to do. I have a large matrix of 31 by 102 size In this, the first 101 colums are independent variables and the 102 is the dependent variable. I am trying to plot automatically the first 101 columns one at a time to the 102nd column wih 102 column lways in the y-axis then fit loarithmic curves to the plots and then list the R2 values for all the plots so far, i have imported the matrix to matlab and created the vectors for each column and then I am trying to figure out how to plot the graphs as i described above. any help will be very much appreciated. thanks, santonu Santonu- I am pretty sure if you search the FEX you'll find something better and this really isn't up to standard for submission to the FEX, but I wanted to play around with this some. So try this function. Notes: Error checking should be added and maybe a way of elminating the initial estimate requirement. Also both functions go into a single m

How to do it?
); //executes a command in a new shell //////////////////////////////////////// hope you know where to include this code ( include it in the main() ) this should do the trick for what you have asked. But if you really want to have some control on what you are executing, then you have to probably go for some Exec() functions.. <seema_coma@yahoo.co.in> wrote in message news:1129035192.163331.245620@o13g2000cwo.googlegroups.com... > Hi all, > I am new to C programming and unix, and I want to write something > similar to this > > if exists ~seema/TimerTest >... and the program failing for some other reason. On some systems, the relationship between executable files and the string you pass to system() is not simple. For example, you might invoke system("foo") to execute "foo.exe" The best solution is likely to be implementation-specific (depending on how much you care about portability). -- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst> We must do something. This is something. Therefore, we must do this.

how to do this
, "ba", 46, 10);} ________________________________________ Looking for a good game? Do it yourself! GLBasic - you can do www.GLBasic.com Gernot Frisch wrote: > > I read a file. When I get an "*" at the beginnig, I write all the data > I read before to another file. > Code: > > while(!feof(file)) a loop like that is allmost always wrong. The reason is that eof gets true only until you try and *failed* to read data from the file. In C++ (and C++) the way to write such a loop is: while( data_can_be_read ) process_data // while loop....\n" "*Last chunk \n" // "of data.\n"); // Works OK // "of data."); // Works OK // "*of data.\n"); // Works OK "*of data."); // FAILS! // Process the file std::string line_buffer; std::string data_accumulator; bool process_data; do { getline(in_file, line_buffer); // Decide what we need to do process_data = (line_buffer.size() > 0 &

do while
is there a matlab command equivalent to the C do while "Deo " <spliers@hotmail.com> wrote in message <g0gt2m$h3q$1@fred.mathworks.com>... > is there a matlab command equivalent to the C do while help while Yes there is, A=5 B=2 while(A > B) C = (A+B)/2 B=B+1 end hope that helped "French Caro " <caro95470@nospam.free.fr> wrote in message <g0gusq$425$1@fred.mathworks.com>... > "Deo " <spliers@hotmail.com> wrote in message > <g0gt2m$h3q$1@fred.mathworks.com>... > > is there a matlab command equivalent to the C do while > help while That was the first place I looked and there was nothing that could help me "Deo " <spliers@hotmail.com> wrote in message <g0gvdm$5tj$1@fred.mathworks.com>... > "French Caro " <caro95470@nospam.free.fr> wrote in message > <g0gusq$425$1@fred.mathworks.com>... > > "Deo " <spliers@hotmail.com> wrote in message > > <g0gt2m$h3q$1@fred.mathworks.com>... > > > is there a matlab command equivalent to the C do while > > help while >

Do-end
Hi All, Can anyone please guide me on Do end,until,while in BASE SAS.Or if you have any document on how to use ,when to use....please do reply or send me the doc.. Thanks in advance, Rajesh.. look in SASHELP on the WWW http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000201927.htm or THE starting point of the online help: http://support.sas.com/onlinedoc/913/docMainpage.jsp Rajesh schreef: > Hi All, > > Can anyone please guide me on Do end,until,while in BASE SAS.Or if > you have any document on how to use ,when to use....please do reply or > send me the doc.. > > Thanks in advance, > Rajesh..

*PinboardOptions
- Release Date: 08/01/04 Sorry, should have checked F12 *help more thoroughly first. I was thrown by the use of single letter parameters whereas help gives fully expanded words. Can you do this with all star command params - just abbreviate params to the initial letter I mean? "neil f" <faz@argonet.co.uk> wrote in message news:4001764a$0$61067$65c69314@mercury.nildram.net... > I'm playing around with an obey file to let me change mode, colours, desktop > layout and pinboard in one click. (See 'Emulating an A4 thread'.) > > Exploring the various mini obey... have checked F12 *help more thoroughly first. I was thrown > by the use of single letter parameters whereas help gives fully expanded > words. Can you do this with all star command params - just abbreviate > params to the initial letter I mean? In general no, this facility must have been explicitly programmed into the pinboard. -- Rik Griffin Standard disclaimer, not speaking for anyone but myself, blah blah In article <400177fb$0$61070$65c69314@mercury.nildram.net>, "neil f" <faz@argonet.co.uk> wrote: > > Sorry, should have checked F12 *help more

What do do about these errors?
getting 3 or 4 errors like this on DKA100 on most days. > > I have DKA100 is in a shadowset with one other disk. =A0I am =A0not > getting errors on other SCSI devices. > > I guess I should replace the disk ASAP? > > Thanks for any input. [...detailed error log omitted...] You asked: "What do do about these errors?" I'll read that as "What to do about these errors?" Answer: Throw them out! Oh, and the disk with them. AEF On 05-01-2011 13:09, brendan welch wrote: > In what I regard as a related item: > > We found that having a disk

How do i do this 300810
I have a script which adds a row. I am using the dom model to do this. I have an image link which is to be inserted next to a input field. How do i do this? I think you have to change the "TD" elemement somehow , also my code has to work in netscape. Has anybody got a solution to this : <head> <script type="text/javascript"> function addRow(id){ var index = document.form1.hidden.value; var tbody = document.getElementById(id).getElementsByTagName("TBODY")[0]; var row = document.createElement("TR"); row.setAttribute("id","row" + index); //Clone this node var targetNode = document.getElementById('SELECT') input1 = targetNode.cloneNode(true) input1.setAttribute("name","select" +index) input2 = document.createElement("input"); input2.setAttribute("name","a" +index) input2.setAttribute("value","") input2.setAttribute("type","text") input2.setAttribute("readOnly","false") input2.setAttribute("size"