Path: news.mathworks.com!not-for-mail
From: "Jeff " <jea@gene.dot.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: divide 1280-by-960 image into 9-by-9
Date: Fri, 27 May 2011 23:08:04 +0000 (UTC)
Organization: Genentech Inc
Lines: 40
Message-ID: <irpask$131$1@newscl01ah.mathworks.com>
References: <irm4h1$jke$1@newscl01ah.mathworks.com> <irm660$ok7$1@newscl01ah.mathworks.com> <irm7rs$lq$1@newscl01ah.mathworks.com> <irmatm$gfc$1@newscl01ah.mathworks.com> <iroa2l$pr5$1@newscl01ah.mathworks.com> <iroh3k$io4$1@newscl01ah.mathworks.com> <irp5js$htg$1@newscl01ah.mathworks.com>
Reply-To: "Jeff " <jea@gene.dot.com>
NNTP-Posting-Host: www-06-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1306537684 1121 172.30.248.38 (27 May 2011 23:08:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 27 May 2011 23:08:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1423763
Xref: news.mathworks.com comp.soft-sys.matlab:729097

"areeba khan" wrote in message <irp5js$htg$1@newscl01ah.mathworks.com>...
> "Jeff " <jea@gene.dot.com> wrote in message <iroh3k$io4$1@newscl01ah.mathworks.com>...
> > "areeba khan" wrote in message <iroa2l$pr5$1@newscl01ah.mathworks.com>...
> > > "Jeff " <jea@gene.dot.com> wrote in message <irmatm$gfc$1@newscl01ah.mathworks.com>...
> > > > grayimg = rgb2gray(imagein);
> > > > 
> > > > padimg = padarray(grayimg, [3 4], 0, 'post'); %modify these values to make your image dimensions divisible by 9
> > > > 
> > > > height = size(padimg,1); %height of full image
> > > > width = size(padimg,2); %width of full image
> > > > 
> > > > n_width = 9;
> > > > m_height = 9;
> > > > 
> > > > for x = 1:m_height:height
> > > >     for y=1:n_width:width
> > > >         image = bigmont(y:y+m_height-1, x:x+n_width-1);
> > > >         imwrite(image,strcat(num2str(x),'^',num2str(y),'.jpg'),'jpg', 'Quality',80);
> > > >     end
> > > > 
> > > > end
> > > >  
> > My apologies.  I went through and renamed some of the variables to more generic names, and missed that one.  Replace "bigmont" with "padimg".
> 
> Jeff,
> thanks for the code..but its reducing the image rather then dividing it..secondly its giving an error
> 
> ??? Index exceeds matrix dimensions
> 
> i try to do it other way round..meanwhile if you have answer to this then please let me know..since i am new to matlab so i am definitely facing such problems..
> thanks

The "Index exceeds matrix dimensions" is probably because you need to change the "3" and "4" in:
padimg = padarray(grayimg, [3 4], 0, 'post');
to give you an image with dimensions evenly divisible by 9.  

For example, you could make your image 963x1267 by using:
padimg = padarray(grayimg, [3 7], 0, 'post');

As far as "reducing the image"...the variable IMAGE is a 9x9 fragment of PADIMAGE that moves across the image, in a typewriter fashion, through PADIMAGE as the X and Y loops increment.  Instead of calling IMWRITE, you could assign it to individual cells in a cell array: (http://www.mathworks.com/help/techdoc/matlab_prog/br04bw6-98.html#br1zng6-1).  Does this make sense?