http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359
MATLAB Central Newsreader  divide 1280by960 image into 9by9
Feed for thread: divide 1280by960 image into 9by9
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Thu, 26 May 2011 18:01:05 +0000
divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838099
areeba khan
i am working on a project detection of skin cancer using image processing..i have found a reference matrix of 9by9 of tumourous cell now through looping i want 2 compare this reference matrix with the image... bt my program is giving this error <br>
??? Error using ==> mat2cell<br>
Number of input vector arguments, 9, does not match the input matrix's number of dimensions, 2. <br>
this is my code<br>
i=imread('E:\cancer images\case 091610\20X1.jpg');<br>
a=rgb2gray(i);<br>
b=imadjust(a);<br>
v=MAT2CELL(b,1,2,3,4,5,6,7,8,9);<br>
mat1=b(725:733,231:239);<br>
c=mat1;<br>
for t=1:size(c,2)<br>
for u=1:size(c,1)<br>
y=xcorr(c(:),b(:));<br>
if y>=0.7<br>
disp('Tumor detected')<br>
else<br>
disp('tumor not found')<br>
end<br>
end<br>
end<br>
please tell me if i am doing right?<br>
tell me some way how i can divide the real image 1280by960 into 9by9?

Thu, 26 May 2011 18:29:20 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838103
Jeff
"areeba khan" wrote in message <irm4h1$jke$1@newscl01ah.mathworks.com>...<br>
> i am working on a project detection of skin cancer using image processing..i have found a reference matrix of 9by9 of tumourous cell now through looping i want 2 compare this reference matrix with the image... bt my program is giving this error <br>
> ??? Error using ==> mat2cell<br>
> Number of input vector arguments, 9, does not match the input matrix's number of dimensions, 2. <br>
> this is my code<br>
> i=imread('E:\cancer images\case 091610\20X1.jpg');<br>
> a=rgb2gray(i);<br>
> b=imadjust(a);<br>
> v=MAT2CELL(b,1,2,3,4,5,6,7,8,9);<br>
> mat1=b(725:733,231:239);<br>
> c=mat1;<br>
> for t=1:size(c,2)<br>
> for u=1:size(c,1)<br>
> y=xcorr(c(:),b(:));<br>
> if y>=0.7<br>
> disp('Tumor detected')<br>
> else<br>
> disp('tumor not found')<br>
> end<br>
> end<br>
> end<br>
> please tell me if i am doing right?<br>
> tell me some way how i can divide the real image 1280by960 into 9by9?<br>
<br>
Well, you're getting an error, so I'm going to go out on a limb and say you're not doing it right. ;)<br>
<br>
If you had an 18x18 pixel image, and wanted to break it into 4 9x9 cells, you could use the mat2cell command:<br>
b= magic(18);<br>
c = mat2cell(b, [9 9], [9 9]);<br>
<br>
But what you want is probably more along the lines of the blockproc function (<a href="http://www.mathworks.com/help/toolbox/images/ref/blockproc.html">http://www.mathworks.com/help/toolbox/images/ref/blockproc.html</a>).

Thu, 26 May 2011 18:53:02 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838110
areeba khan
"Jeff " <jea@gene.dot.com> wrote in message <irm660$ok7$1@newscl01ah.mathworks.com>...<br>
> "areeba khan" wrote in message <irm4h1$jke$1@newscl01ah.mathworks.com>...<br>
> > i am working on a project detection of skin cancer using image processing..i have found a reference matrix of 9by9 of tumourous cell now through looping i want 2 compare this reference matrix with the image... bt my program is giving this error <br>
> > ??? Error using ==> mat2cell<br>
> > Number of input vector arguments, 9, does not match the input matrix's number of dimensions, 2. <br>
> > this is my code<br>
> > i=imread('E:\cancer images\case 091610\20X1.jpg');<br>
> > a=rgb2gray(i);<br>
> > b=imadjust(a);<br>
> > v=MAT2CELL(b,1,2,3,4,5,6,7,8,9);<br>
> > mat1=b(725:733,231:239);<br>
> > c=mat1;<br>
> > for t=1:size(c,2)<br>
> > for u=1:size(c,1)<br>
> > y=xcorr(c(:),b(:));<br>
> > if y>=0.7<br>
> > disp('Tumor detected')<br>
> > else<br>
> > disp('tumor not found')<br>
> > end<br>
> > end<br>
> > end<br>
> > please tell me if i am doing right?<br>
> > tell me some way how i can divide the real image 1280by960 into 9by9?<br>
> <br>
> Well, you're getting an error, so I'm going to go out on a limb and say you're not doing it right. ;)<br>
> <br>
> If you had an 18x18 pixel image, and wanted to break it into 4 9x9 cells, you could use the mat2cell command:<br>
> b= magic(18);<br>
> c = mat2cell(b, [9 9], [9 9]);<br>
> <br>
> But what you want is probably more along the lines of the blockproc function (<a href="http://www.mathworks.com/help/toolbox/images/ref/blockproc.html">http://www.mathworks.com/help/toolbox/images/ref/blockproc.html</a>).<br>
<br>
<br>
i m not getting your point. as far as i get it, the use of magic command doesn't seem to be relevant to my task...can u please guide me how can i break the image (960by1280) into a 9by9 matrix?

Thu, 26 May 2011 18:58:04 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838111
areeba khan
"Jeff " <jea@gene.dot.com> wrote in message <irm660$ok7$1@newscl01ah.mathworks.com>...<br>
> "areeba khan" wrote in message <irm4h1$jke$1@newscl01ah.mathworks.com>...<br>
> > i am working on a project detection of skin cancer using image processing..i have found a reference matrix of 9by9 of tumourous cell now through looping i want 2 compare this reference matrix with the image... bt my program is giving this error <br>
> > ??? Error using ==> mat2cell<br>
> > Number of input vector arguments, 9, does not match the input matrix's number of dimensions, 2. <br>
> > this is my code<br>
> > i=imread('E:\cancer images\case 091610\20X1.jpg');<br>
> > a=rgb2gray(i);<br>
> > b=imadjust(a);<br>
> > v=MAT2CELL(b,1,2,3,4,5,6,7,8,9);<br>
> > mat1=b(725:733,231:239);<br>
> > c=mat1;<br>
> > for t=1:size(c,2)<br>
> > for u=1:size(c,1)<br>
> > y=xcorr(c(:),b(:));<br>
> > if y>=0.7<br>
> > disp('Tumor detected')<br>
> > else<br>
> > disp('tumor not found')<br>
> > end<br>
> > end<br>
> > end<br>
> > please tell me if i am doing right?<br>
> > tell me some way how i can divide the real image 1280by960 into 9by9?<br>
> <br>
> Well, you're getting an error, so I'm going to go out on a limb and say you're not doing it right. ;)<br>
> <br>
> If you had an 18x18 pixel image, and wanted to break it into 4 9x9 cells, you could use the mat2cell command:<br>
> b= magic(18);<br>
> c = mat2cell(b, [9 9], [9 9]);<br>
> <br>
> But what you want is probably more along the lines of the blockproc function (<a href="http://www.mathworks.com/help/toolbox/images/ref/blockproc.html">http://www.mathworks.com/help/toolbox/images/ref/blockproc.html</a>).<br>
<br>
as far as i get it, the use of magic command doesn't seem to be relevant for my task..can u please guide me how can i divide/break the 960by1280 image into 9by9 cells?

Thu, 26 May 2011 19:12:05 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838112
Florin Neacsu
"areeba khan" wrote in message <irm4h1$jke$1@newscl01ah.mathworks.com>...<br>
> i am working on a project detection of skin cancer using image processing..i have found a reference matrix of 9by9 of tumourous cell now through looping i want 2 compare this reference matrix with the image... bt my program is giving this error <br>
> ??? Error using ==> mat2cell<br>
> Number of input vector arguments, 9, does not match the input matrix's number of dimensions, 2. <br>
> this is my code<br>
> i=imread('E:\cancer images\case 091610\20X1.jpg');<br>
> a=rgb2gray(i);<br>
> b=imadjust(a);<br>
> v=MAT2CELL(b,1,2,3,4,5,6,7,8,9);<br>
> mat1=b(725:733,231:239);<br>
> c=mat1;<br>
> for t=1:size(c,2)<br>
> for u=1:size(c,1)<br>
> y=xcorr(c(:),b(:));<br>
> if y>=0.7<br>
> disp('Tumor detected')<br>
> else<br>
> disp('tumor not found')<br>
> end<br>
> end<br>
> end<br>
> please tell me if i am doing right?<br>
> tell me some way how i can divide the real image 1280by960 into 9by9?<br>
<br>
Hello,<br>
<br>
May I suggest something ? Please reformulate your question. Looking at your words and then at your code is very confusing !<br>
<br>
Are you trying to analyze a 9x9 chunk of the big matrix ? What are you going to do at the borders? Where are you using "v" in your code , after that attempt of allocation? Why are you doing 81 times the same operation ? ...<br>
<br>
Regards,<br>
Florin

Thu, 26 May 2011 19:50:14 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838116
Jeff
"areeba khan" wrote in message <irm7rs$lq$1@newscl01ah.mathworks.com>...<br>
> "Jeff " <jea@gene.dot.com> wrote in message <irm660$ok7$1@newscl01ah.mathworks.com>...<br>
> > "areeba khan" wrote in message <irm4h1$jke$1@newscl01ah.mathworks.com>...<br>
> > > i am working on a project detection of skin cancer using image processing..i have found a reference matrix of 9by9 of tumourous cell now through looping i want 2 compare this reference matrix with the image... bt my program is giving this error <br>
> > > ??? Error using ==> mat2cell<br>
> > > Number of input vector arguments, 9, does not match the input matrix's number of dimensions, 2. <br>
> > > this is my code<br>
> > > i=imread('E:\cancer images\case 091610\20X1.jpg');<br>
> > > a=rgb2gray(i);<br>
> > > b=imadjust(a);<br>
> > > v=MAT2CELL(b,1,2,3,4,5,6,7,8,9);<br>
> > > mat1=b(725:733,231:239);<br>
> > > c=mat1;<br>
> > > for t=1:size(c,2)<br>
> > > for u=1:size(c,1)<br>
> > > y=xcorr(c(:),b(:));<br>
> > > if y>=0.7<br>
> > > disp('Tumor detected')<br>
> > > else<br>
> > > disp('tumor not found')<br>
> > > end<br>
> > > end<br>
> > > end<br>
> > > please tell me if i am doing right?<br>
> > > tell me some way how i can divide the real image 1280by960 into 9by9?<br>
> > <br>
> > Well, you're getting an error, so I'm going to go out on a limb and say you're not doing it right. ;)<br>
> > <br>
> > If you had an 18x18 pixel image, and wanted to break it into 4 9x9 cells, you could use the mat2cell command:<br>
> > b= magic(18);<br>
> > c = mat2cell(b, [9 9], [9 9]);<br>
> > <br>
> > But what you want is probably more along the lines of the blockproc function (<a href="http://www.mathworks.com/help/toolbox/images/ref/blockproc.html">http://www.mathworks.com/help/toolbox/images/ref/blockproc.html</a>).<br>
> <br>
> as far as i get it, the use of magic command doesn't seem to be relevant for my task..can u please guide me how can i divide/break the 960by1280 image into 9by9 cells?<br>
<br>
Did you look at the blockproc function? Particularly the example at:<br>
<a href="http://www.mathworks.com/help/toolbox/images/f712726.html#brcu20d1">http://www.mathworks.com/help/toolbox/images/f712726.html#brcu20d1</a><br>
You can call your comparison metric as the function, but getting your raw image and index into the same image may be tricky.<br>
<br>
Failing that, you'll first need to figure out what you want to do with the remainders, since 9 is not evenly divisible into 960 nor 1280. I would suggest using padarray.<br>
<br>
After you have something that is evenly divisible, take a look at the code below. It performs an arbitrary operation, imwrite, where you would want to put your comparison:<br>
<br>
grayimg = rgb2gray(imagein);<br>
<br>
padimg = padarray(grayimg, [3 4], 0, 'post'); %modify these values to make your image dimensions divisible by 9<br>
<br>
height = size(padimg,1); %height of full image<br>
width = size(padimg,2); %width of full image<br>
<br>
n_width = 9;<br>
m_height = 9;<br>
<br>
for x = 1:m_height:height<br>
for y=1:n_width:width<br>
image = bigmont(y:y+m_height1, x:x+n_width1);<br>
imwrite(image,strcat(num2str(x),'^',num2str(y),'.jpg'),'jpg', 'Quality',80);<br>
end<br>
<br>
end<br>

Thu, 26 May 2011 20:42:02 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838129
Roger Stafford
"areeba khan" wrote in message <irm4h1$jke$1@newscl01ah.mathworks.com>...<br>
> i am working on a project detection of skin cancer using image processing..i have found a reference matrix of 9by9 of tumourous cell now through looping i want 2 compare this reference matrix with the image... bt my program is giving this error <br>
> ??? Error using ==> mat2cell<br>
> Number of input vector arguments, 9, does not match the input matrix's number of dimensions, 2. <br>
> this is my code<br>
> i=imread('E:\cancer images\case 091610\20X1.jpg');<br>
> a=rgb2gray(i);<br>
> b=imadjust(a);<br>
> v=MAT2CELL(b,1,2,3,4,5,6,7,8,9);<br>
> mat1=b(725:733,231:239);<br>
> c=mat1;<br>
> for t=1:size(c,2)<br>
> for u=1:size(c,1)<br>
> y=xcorr(c(:),b(:));<br>
> if y>=0.7<br>
> disp('Tumor detected')<br>
> else<br>
> disp('tumor not found')<br>
> end<br>
> end<br>
> end<br>
> please tell me if i am doing right?<br>
> tell me some way how i can divide the real image 1280by960 into 9by9?<br>
         <br>
In my opinion it is unwise to partition your matrix b into separate nonoverlapping 9 by 9 blocks. Doing things that way runs the high risk of possibly missing the particular 9 by 9 portion where correlation with your reference matrix is highest, and with something as vital as cancer you don't want to miss important clues.<br>
<br>
Using 'xcorr' with c(:) and b(:) as you have done is also highly inappropriate since you would be correlating c with the wrong 9element groups within b. I would think that a single call on 'xcorr2' with arguments b and c (not reshaped to vectors) is far more suited to your needs. However, its output needs to be normalized to make it easier to interpret. You should make a careful study of the 'xcorr2' documentation. There is an example given there of how normalization can be done, but if you find that too difficult to achieve, you should ask about it here.<br>
<br>
Roger Stafford

Fri, 27 May 2011 02:25:57 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838155
ImageAnalyst
areeba khan:<br>
Cross correlation is not a reliable way to do pattern matching. You<br>
think that correlating your template over your image will give a spike<br>
where your template is located in your main image. I know you think<br>
that and I know you've been told that, and so was I, . . . and I even<br>
thought that until I learned that it is not true. Heck, even the<br>
MATLAB help gives this incorrect statement: "xcorr2 is the two<br>
dimensional version of xcorr. It has its maximum value when the two<br>
matrices are aligned so that they are shaped as similarly as<br>
possible." That is not true in general, only for certain cases. The<br>
code below demonstrates a case where it's not true:<br>
<br>
% IMPORTANT: The newsreader may break long lines into multiple lines.<br>
% Be sure to join any long lines that got split into multiple single<br>
lines.<br>
% These can be found by the red lines on the left side of your<br>
% text editor, which indicate syntax errors, or else just run the<br>
% code and it will stop at the split lines with an error.<br>
<br>
% Script to demonstrate that the max value of a cross correlation<br>
% is not always where the template is located.<br>
clc;<br>
clear all;<br>
workspace;<br>
<br>
% Change the current folder to the folder of this mfile.<br>
if(~isdeployed)<br>
cd(fileparts(which(mfilename)));<br>
end<br>
<br>
% Check that user has the Signal Processing Toolbox installed.<br>
hasRequiredToolbox = license('test', 'signal_toolbox');<br>
if ~hasRequiredToolbox<br>
% User does not have the toolbox installed.<br>
message = sprintf('Sorry, but you do not seem to have the Signal<br>
Processing Toolbox.\nDo you want to try to continue anyway?');<br>
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');<br>
if strcmpi(reply, 'No')<br>
% User said No, so exit.<br>
return;<br>
end<br>
end<br>
<br>
% Define image 1<br>
I1 = [1 2 3 100 100<br>
11 5 8 100 100<br>
4 6 13 100 100<br>
10 12 15 100 100<br>
100 100 100 100 100]<br>
<br>
%Define image 2 = I1(2:4, 1:3)<br>
I2 = [11 5 8<br>
4 6 13<br>
10 12 15]<br>
<br>
% First do the regular cross correlation.<br>
c = xcorr2(I1, I2)<br>
<br>
% I2 is aligned with I1 at row 4, column 3<br>
% of the cross correlation matrix.<br>
% Remember the cross correlation matrix is bigger than either one.<br>
% Let's see if the max is really at row 4, column 3,<br>
% where you think it should be.<br>
[maxRow maxCol] = find(c == max(c(:)))<br>
% Nope, it's not. Hmmmmm.....<br>
<br>
% OK that didn't turn out as expected.<br>
% So now let's try "normalized" cross correlation.<br>
% Normalize each image.<br>
i1n = (I1  mean2(I1)) / std(I1(:))<br>
i2n = (I2  mean2(I2)) / std(I2(:))<br>
% Now do the cross correlation with the normalized versions.<br>
cn = xcorr2(i1n, i2n)<br>
% See if it is max at the aligned spot.<br>
[maxRow maxCol] = find(cn == max(cn(:)))<br>
% Nope, it's not either.<br>
% What have we learned here?<br>
<br>
====================================<br>
I1 =<br>
1 2 3 100 100<br>
11 5 8 100 100<br>
4 6 13 100 100<br>
10 12 15 100 100<br>
100 100 100 100 100<br>
<br>
<br>
I2 =<br>
11 5 8<br>
4 6 13<br>
10 12 15<br>
<br>
<br>
c =<br>
15 42 79 1556 2730<br>
2200 1000<br>
178 239 345 2972 4692<br>
3200 1400<br>
211 290 530 3921 6095<br>
4800 2500<br>
290 497 900 4097 6190<br>
4800 2500<br>
1662 2984 4185 6069 7103<br>
4800 2500<br>
1380 2046 2590 3307 3765<br>
2600 1500<br>
800 1300 2400 2400 2400<br>
1600 1100<br>
<br>
maxRow =<br>
5<br>
<br>
maxCol =<br>
5<br>
<br>
i1n =<br>
1.1550 1.1339 1.1127 0.9393 0.9393<br>
0.9435 1.0704 1.0070 0.9393 0.9393<br>
1.0916 1.0493 0.9012 0.9393 0.9393<br>
0.9646 0.9223 0.8589 0.9393 0.9393<br>
0.9393 0.9393 0.9393 0.9393 0.9393<br>
<br>
<br>
i2n =<br>
0.4377 1.1380 0.3502<br>
1.4006 0.8754 0.9629<br>
0.1751 0.7003 1.4881<br>
<br>
<br>
cn =<br>
1.7189 2.4962 2.6522 0.4200 1.8607 0.8222 0.1644<br>
2.5162 2.3344 0.8744 3.9718 3.5199 1.3155 1.1511<br>
2.1285 0.8192 0.1963 4.3092 1.5055 1.9733 0.7400<br>
2.1562 0.6544 0.6444 4.1462 1.4111 1.9733 0.7400<br>
0.8511 3.6214 4.5832 5.4054 1.7129 1.9733 0.7400<br>
1.2422 1.5029 0.3052 0.9885 3.0070 2.7955 0.9044<br>
0.3289 1.3977 0.9866 0.9866 0.9866 0.6578 0.4111<br>
<br>
maxRow =<br>
5<br>
<br>
maxCol =<br>
4

Fri, 27 May 2011 04:19:04 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838165
Roger Stafford
ImageAnalyst <imageanalyst@mailinator.com> wrote in message <5d9de2331504487b966361aea7de2bf8@s9g2000yqm.googlegroups.com>...<br>
> areeba khan:<br>
> Cross correlation is not a reliable way to do pattern matching. .....<br>
> .......<br>
> % Define image 1<br>
> I1 = [1 2 3 100 100<br>
> 11 5 8 100 100<br>
> 4 6 13 100 100<br>
> 10 12 15 100 100<br>
> 100 100 100 100 100]<br>
> <br>
> %Define image 2 = I1(2:4, 1:3)<br>
> I2 = [11 5 8<br>
> 4 6 13<br>
> 10 12 15]<br>
> ........<br>
> % Now do the cross correlation with the normalized versions.<br>
> ........<br>
> cn =<br>
> 1.7189 2.4962 2.6522 0.4200 1.8607 0.8222 0.1644<br>
> 2.5162 2.3344 0.8744 3.9718 3.5199 1.3155 1.1511<br>
> 2.1285 0.8192 0.1963 4.3092 1.5055 1.9733 0.7400<br>
> 2.1562 0.6544 0.6444 4.1462 1.4111 1.9733 0.7400<br>
> 0.8511 3.6214 4.5832 5.4054 1.7129 1.9733 0.7400<br>
> 1.2422 1.5029 0.3052 0.9885 3.0070 2.7955 0.9044<br>
> 0.3289 1.3977 0.9866 0.9866 0.9866 0.6578 0.4111<br>
> ........<br>
         <br>
Hello ImageAnalyst. In the second of your examples here you have used 'xcorr2' on two matrices which have been normalized. However, there is a very important difference between doing things this way, and performing the kind of normalization that is described in the documentation for 'xcorr2', (even though they apparently don't actually perform that in the 'xcorr2' results, though there is an easy way of using 'xcorr2' so as to accomplish it.)<br>
<br>
To show what I mean, in your example above with I1 and I2, to get the entry at (3,3) they (Mathworks) describe how they would/could do normalization:<br>
<br>
(1*11+2*5+3*8+11*4+5*6+8*13+4*10+6*12+13*15) /<br>
sqrt(1^2+2^2+3^2+11^2+5^2+8^2+4^2+6^2+13^1) /<br>
sqrt(11^2+5^2+8^2+4^2+6^2+13^2+10^2+12^2+15^2) = 0.83748<br>
<br>
The whole inner 3 x 3 set would be as follows.<br>
<br>
c(3:5,3:5) =<br>
<br>
0.83748031821396 0.75076516439463 0.82775681371927<br>
1.00000000000000 0.77989724776256 0.83915561746709<br>
0.79629825385399 0.89956433917556 0.89238597884516<br>
<br>
(Note that seven of these have involved the "100" entries.)<br>
<br>
As you see, the entry at (4,3) where I2 is identical to I1(2:4,1:3) is now maximum at 1.0000 while all others are less than 1. The entry at (5,4) which was the maximum at 5.4054 in your example is now down to a modest 0.899564, well below 1. It can be proved that 1 can only be achieved by identical matches. All values must lie between 1 and +1, (as any selfrespecting correlation value ought to.)<br>
<br>
This is why, in my previous article in this thread, I recommended normalization to Areeba in the event that 'xcorr2' were to be used. I had this kind of normalization in mind.<br>
<br>
Roger Stafford

Fri, 27 May 2011 05:08:04 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838168
Roger Stafford
"Roger Stafford" wrote in message <irn8no$32h$1@newscl01ah.mathworks.com>...<br>
> ...... It can be proved that 1 can only be achieved by identical matches. .....<br>
        <br>
Where I said, "It can be proved that a 1 can only be achieved by identical matches", that is not correct. A correct statement is that a 1 can only be achieved by proportional matrices  that is, when all ratios between corresponding elements are equal.<br>
<br>
Roger Stafford

Fri, 27 May 2011 13:48:05 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838230
areeba khan
"Jeff " <jea@gene.dot.com> wrote in message <irmatm$gfc$1@newscl01ah.mathworks.com>...<br>
> "areeba khan" wrote in message <irm7rs$lq$1@newscl01ah.mathworks.com>...<br>
> > "Jeff " <jea@gene.dot.com> wrote in message <irm660$ok7$1@newscl01ah.mathworks.com>...<br>
> > > "areeba khan" wrote in message <irm4h1$jke$1@newscl01ah.mathworks.com>...<br>
> > > > i am working on a project detection of skin cancer using image processing..i have found a reference matrix of 9by9 of tumourous cell now through looping i want 2 compare this reference matrix with the image... bt my program is giving this error <br>
> > > > ??? Error using ==> mat2cell<br>
> > > > Number of input vector arguments, 9, does not match the input matrix's number of dimensions, 2. <br>
> > > > this is my code<br>
> > > > i=imread('E:\cancer images\case 091610\20X1.jpg');<br>
> > > > a=rgb2gray(i);<br>
> > > > b=imadjust(a);<br>
> > > > v=MAT2CELL(b,1,2,3,4,5,6,7,8,9);<br>
> > > > mat1=b(725:733,231:239);<br>
> > > > c=mat1;<br>
> > > > for t=1:size(c,2)<br>
> > > > for u=1:size(c,1)<br>
> > > > y=xcorr(c(:),b(:));<br>
> > > > if y>=0.7<br>
> > > > disp('Tumor detected')<br>
> > > > else<br>
> > > > disp('tumor not found')<br>
> > > > end<br>
> > > > end<br>
> > > > end<br>
> > > > please tell me if i am doing right?<br>
> > > > tell me some way how i can divide the real image 1280by960 into 9by9?<br>
> > > <br>
> > > Well, you're getting an error, so I'm going to go out on a limb and say you're not doing it right. ;)<br>
> > > <br>
> > > If you had an 18x18 pixel image, and wanted to break it into 4 9x9 cells, you could use the mat2cell command:<br>
> > > b= magic(18);<br>
> > > c = mat2cell(b, [9 9], [9 9]);<br>
> > > <br>
> > > But what you want is probably more along the lines of the blockproc function (<a href="http://www.mathworks.com/help/toolbox/images/ref/blockproc.html">http://www.mathworks.com/help/toolbox/images/ref/blockproc.html</a>).<br>
> > <br>
> > as far as i get it, the use of magic command doesn't seem to be relevant for my task..can u please guide me how can i divide/break the 960by1280 image into 9by9 cells?<br>
> <br>
> Did you look at the blockproc function? Particularly the example at:<br>
> <a href="http://www.mathworks.com/help/toolbox/images/f712726.html#brcu20d1">http://www.mathworks.com/help/toolbox/images/f712726.html#brcu20d1</a><br>
> You can call your comparison metric as the function, but getting your raw image and index into the same image may be tricky.<br>
> <br>
> Failing that, you'll first need to figure out what you want to do with the remainders, since 9 is not evenly divisible into 960 nor 1280. I would suggest using padarray.<br>
> <br>
> After you have something that is evenly divisible, take a look at the code below. It performs an arbitrary operation, imwrite, where you would want to put your comparison:<br>
> <br>
> grayimg = rgb2gray(imagein);<br>
> <br>
> padimg = padarray(grayimg, [3 4], 0, 'post'); %modify these values to make your image dimensions divisible by 9<br>
> <br>
> height = size(padimg,1); %height of full image<br>
> width = size(padimg,2); %width of full image<br>
> <br>
> n_width = 9;<br>
> m_height = 9;<br>
> <br>
> for x = 1:m_height:height<br>
> for y=1:n_width:width<br>
> image = bigmont(y:y+m_height1, x:x+n_width1);<br>
> imwrite(image,strcat(num2str(x),'^',num2str(y),'.jpg'),'jpg', 'Quality',80);<br>
> end<br>
> <br>
> end<br>
> <br>
<br>
thank you Jeff..this might help me but can you please tell me what does bigmont do? as i m new to MATLAB and uptill now i have not found any such command..infact not in the help..i would be grateful if you please explain it..also please tell me can i take anyother value of quality

Fri, 27 May 2011 13:58:02 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838233
areeba khan
"Florin Neacsu" wrote in message <irm8m5$58n$1@newscl01ah.mathworks.com>...<br>
> "areeba khan" wrote in message <irm4h1$jke$1@newscl01ah.mathworks.com>...<br>
> > i am working on a project detection of skin cancer using image processing..i have found a reference matrix of 9by9 of tumourous cell now through looping i want 2 compare this reference matrix with the image... bt my program is giving this error <br>
> > ??? Error using ==> mat2cell<br>
> > Number of input vector arguments, 9, does not match the input matrix's number of dimensions, 2. <br>
> > this is my code<br>
> > i=imread('E:\cancer images\case 091610\20X1.jpg');<br>
> > a=rgb2gray(i);<br>
> > b=imadjust(a);<br>
> > v=MAT2CELL(b,1,2,3,4,5,6,7,8,9);<br>
> > mat1=b(725:733,231:239);<br>
> > c=mat1;<br>
> > for t=1:size(c,2)<br>
> > for u=1:size(c,1)<br>
> > y=xcorr(c(:),b(:));<br>
> > if y>=0.7<br>
> > disp('Tumor detected')<br>
> > else<br>
> > disp('tumor not found')<br>
> > end<br>
> > end<br>
> > end<br>
> > please tell me if i am doing right?<br>
> > tell me some way how i can divide the real image 1280by960 into 9by9?<br>
> <br>
> Hello,<br>
> <br>
> May I suggest something ? Please reformulate your question. Looking at your words and then at your code is very confusing !<br>
> <br>
> Are you trying to analyze a 9x9 chunk of the big matrix ? What are you going to do at the borders? Where are you using "v" in your code , after that attempt of allocation? Why are you doing 81 times the same operation ? ...<br>
> <br>
> Regards,<br>
> Florin<br>
<br>
hello Florin,<br>
yes, i think you got my point.<br>
Actually, I have an image of size 960by1280 and i need to break this matrix into 9by9 so that i can compare or rather correlate it with a reference matrix of size 9by9 (given as mat1 in the code). As far as i know, the command mat2cell is used to break a big matrix into smaller cells that is why i m using this for the aforesaid purpose. i need to compare all the cells (obtained after breaking b, the big matrix, into smaller cells) with mat1. i know i m making some blunder but i hope now my query is clear to you.can you please guide me of some proper way to break a big matrix into smaller chunks and correlating it with the reference matrix?<br>
<br>
thanks,<br>
areeba

Fri, 27 May 2011 14:23:05 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838236
areeba khan
"Roger Stafford" wrote in message <irmduq$qe2$1@newscl01ah.mathworks.com>...<br>
> "areeba khan" wrote in message <irm4h1$jke$1@newscl01ah.mathworks.com>...<br>
> > i am working on a project detection of skin cancer using image processing..i have found a reference matrix of 9by9 of tumourous cell now through looping i want 2 compare this reference matrix with the image... bt my program is giving this error <br>
> > ??? Error using ==> mat2cell<br>
> > Number of input vector arguments, 9, does not match the input matrix's number of dimensions, 2. <br>
> > this is my code<br>
> > i=imread('E:\cancer images\case 091610\20X1.jpg');<br>
> > a=rgb2gray(i);<br>
> > b=imadjust(a);<br>
> > v=MAT2CELL(b,1,2,3,4,5,6,7,8,9);<br>
> > mat1=b(725:733,231:239);<br>
> > c=mat1;<br>
> > for t=1:size(c,2)<br>
> > for u=1:size(c,1)<br>
> > y=xcorr(c(:),b(:));<br>
> > if y>=0.7<br>
> > disp('Tumor detected')<br>
> > else<br>
> > disp('tumor not found')<br>
> > end<br>
> > end<br>
> > end<br>
> > please tell me if i am doing right?<br>
> > tell me some way how i can divide the real image 1280by960 into 9by9?<br>
>          <br>
> In my opinion it is unwise to partition your matrix b into separate nonoverlapping 9 by 9 blocks. Doing things that way runs the high risk of possibly missing the particular 9 by 9 portion where correlation with your reference matrix is highest, and with something as vital as cancer you don't want to miss important clues.<br>
> <br>
> Using 'xcorr' with c(:) and b(:) as you have done is also highly inappropriate since you would be correlating c with the wrong 9element groups within b. I would think that a single call on 'xcorr2' with arguments b and c (not reshaped to vectors) is far more suited to your needs. However, its output needs to be normalized to make it easier to interpret. You should make a careful study of the 'xcorr2' documentation. There is an example given there of how normalization can be done, but if you find that too difficult to achieve, you should ask about it here.<br>
> <br>
> Roger Stafford<br>
<br>
thank you Mr. Stafford..i'll also try this way and if i find any difficulty i'll surely be asking you here.. but what makes me confused right now is that do i still need to break the big matrix into smaller cells or should i do it the way you are suggesting?

Fri, 27 May 2011 15:15:16 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838246
ImageAnalyst
On May 27, 1:08 am, "Roger Stafford"<br>
<ellieandrogerxy...@mindspring.com.invalid> wrote:<br>
> "Roger Stafford" wrote in message <irn8no$32...@newscl01ah.mathworks.com>...<br>
> > ...... It can be proved that 1 can only be achieved by identical matches. .....<br>
><br>
>         <br>
> Where I said, "It can be proved that a 1 can only be achieved by identical matches", that is not correct. A correct statement is that a 1 can only be achieved by proportional matrices  that is, when all ratios between corresponding elements are equal.<br>
><br>
> Roger Stafford<br>
<br>
<br>
Roger:<br>
Wow, kind of tricky and unintuitive. Not sure I follow completely. I<br>
didn't see any explanation in xcorr2's help about how to normalize<br>
your input arrays before calling xcorr2, unless you're referring to<br>
this terse entry:<br>
"The normalized crosscorrelation of the (2,4) output element is<br>
585/sqrt(sum(dot(I1p,I1p))*sum(dot(I2,I2))) = 0.8070"<br>
Is that what you did? Is that their "explanation"? I don't really<br>
see from the above how that tells me to normalize my input arrays. If<br>
that is what you need to do to fix up your inputs to get a spike at<br>
the alignment spot, then I bet it will be overlooked by the vast<br>
majority of people who will just blindly apply the correlation and<br>
expect to see a spike at the "right" place. How would you fix up my<br>
code to give a spike (value of 1.000) at the proper 4,3 location?<br>
ImageAnalyst

Fri, 27 May 2011 15:48:04 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838247
Jeff
"areeba khan" wrote in message <iroa2l$pr5$1@newscl01ah.mathworks.com>...<br>
> "Jeff " <jea@gene.dot.com> wrote in message <irmatm$gfc$1@newscl01ah.mathworks.com>...<br>
> > "areeba khan" wrote in message <irm7rs$lq$1@newscl01ah.mathworks.com>...<br>
> > > "Jeff " <jea@gene.dot.com> wrote in message <irm660$ok7$1@newscl01ah.mathworks.com>...<br>
> > > > "areeba khan" wrote in message <irm4h1$jke$1@newscl01ah.mathworks.com>...<br>
> > > > > i am working on a project detection of skin cancer using image processing..i have found a reference matrix of 9by9 of tumourous cell now through looping i want 2 compare this reference matrix with the image... bt my program is giving this error <br>
> > > > > ??? Error using ==> mat2cell<br>
> > > > > Number of input vector arguments, 9, does not match the input matrix's number of dimensions, 2. <br>
> > > > > this is my code<br>
> > > > > i=imread('E:\cancer images\case 091610\20X1.jpg');<br>
> > > > > a=rgb2gray(i);<br>
> > > > > b=imadjust(a);<br>
> > > > > v=MAT2CELL(b,1,2,3,4,5,6,7,8,9);<br>
> > > > > mat1=b(725:733,231:239);<br>
> > > > > c=mat1;<br>
> > > > > for t=1:size(c,2)<br>
> > > > > for u=1:size(c,1)<br>
> > > > > y=xcorr(c(:),b(:));<br>
> > > > > if y>=0.7<br>
> > > > > disp('Tumor detected')<br>
> > > > > else<br>
> > > > > disp('tumor not found')<br>
> > > > > end<br>
> > > > > end<br>
> > > > > end<br>
> > > > > please tell me if i am doing right?<br>
> > > > > tell me some way how i can divide the real image 1280by960 into 9by9?<br>
> > > > <br>
> > > > Well, you're getting an error, so I'm going to go out on a limb and say you're not doing it right. ;)<br>
> > > > <br>
> > > > If you had an 18x18 pixel image, and wanted to break it into 4 9x9 cells, you could use the mat2cell command:<br>
> > > > b= magic(18);<br>
> > > > c = mat2cell(b, [9 9], [9 9]);<br>
> > > > <br>
> > > > But what you want is probably more along the lines of the blockproc function (<a href="http://www.mathworks.com/help/toolbox/images/ref/blockproc.html">http://www.mathworks.com/help/toolbox/images/ref/blockproc.html</a>).<br>
> > > <br>
> > > as far as i get it, the use of magic command doesn't seem to be relevant for my task..can u please guide me how can i divide/break the 960by1280 image into 9by9 cells?<br>
> > <br>
> > Did you look at the blockproc function? Particularly the example at:<br>
> > <a href="http://www.mathworks.com/help/toolbox/images/f712726.html#brcu20d1">http://www.mathworks.com/help/toolbox/images/f712726.html#brcu20d1</a><br>
> > You can call your comparison metric as the function, but getting your raw image and index into the same image may be tricky.<br>
> > <br>
> > Failing that, you'll first need to figure out what you want to do with the remainders, since 9 is not evenly divisible into 960 nor 1280. I would suggest using padarray.<br>
> > <br>
> > After you have something that is evenly divisible, take a look at the code below. It performs an arbitrary operation, imwrite, where you would want to put your comparison:<br>
> > <br>
> > grayimg = rgb2gray(imagein);<br>
> > <br>
> > padimg = padarray(grayimg, [3 4], 0, 'post'); %modify these values to make your image dimensions divisible by 9<br>
> > <br>
> > height = size(padimg,1); %height of full image<br>
> > width = size(padimg,2); %width of full image<br>
> > <br>
> > n_width = 9;<br>
> > m_height = 9;<br>
> > <br>
> > for x = 1:m_height:height<br>
> > for y=1:n_width:width<br>
> > image = bigmont(y:y+m_height1, x:x+n_width1);<br>
> > imwrite(image,strcat(num2str(x),'^',num2str(y),'.jpg'),'jpg', 'Quality',80);<br>
> > end<br>
> > <br>
> > end<br>
> > <br>
> <br>
> thank you Jeff..this might help me but can you please tell me what does bigmont do? as i m new to MATLAB and uptill now i have not found any such command..infact not in the help..i would be grateful if you please explain it..also please tell me can i take anyother value of quality<br>
<br>
My apologies. I went through and renamed some of the variables to more generic names, and missed that one. Replace "bigmont" with "padimg".

Fri, 27 May 2011 17:04:04 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838257
Florin Neacsu
"areeba khan" wrote in message <iroala$ric$1@newscl01ah.mathworks.com>...<br>
> "Florin Neacsu" wrote in message <irm8m5$58n$1@newscl01ah.mathworks.com>...<br>
> > "areeba khan" wrote in message <irm4h1$jke$1@newscl01ah.mathworks.com>...<br>
> > > i am working on a project detection of skin cancer using image processing..i have found a reference matrix of 9by9 of tumourous cell now through looping i want 2 compare this reference matrix with the image... bt my program is giving this error <br>
> > > ??? Error using ==> mat2cell<br>
> > > Number of input vector arguments, 9, does not match the input matrix's number of dimensions, 2. <br>
> > > this is my code<br>
> > > i=imread('E:\cancer images\case 091610\20X1.jpg');<br>
> > > a=rgb2gray(i);<br>
> > > b=imadjust(a);<br>
> > > v=MAT2CELL(b,1,2,3,4,5,6,7,8,9);<br>
> > > mat1=b(725:733,231:239);<br>
> > > c=mat1;<br>
> > > for t=1:size(c,2)<br>
> > > for u=1:size(c,1)<br>
> > > y=xcorr(c(:),b(:));<br>
> > > if y>=0.7<br>
> > > disp('Tumor detected')<br>
> > > else<br>
> > > disp('tumor not found')<br>
> > > end<br>
> > > end<br>
> > > end<br>
> > > please tell me if i am doing right?<br>
> > > tell me some way how i can divide the real image 1280by960 into 9by9?<br>
> > <br>
> > Hello,<br>
> > <br>
> > May I suggest something ? Please reformulate your question. Looking at your words and then at your code is very confusing !<br>
> > <br>
> > Are you trying to analyze a 9x9 chunk of the big matrix ? What are you going to do at the borders? Where are you using "v" in your code , after that attempt of allocation? Why are you doing 81 times the same operation ? ...<br>
> > <br>
> > Regards,<br>
> > Florin<br>
> <br>
> hello Florin,<br>
> yes, i think you got my point.<br>
> Actually, I have an image of size 960by1280 and i need to break this matrix into 9by9 so that i can compare or rather correlate it with a reference matrix of size 9by9 (given as mat1 in the code). As far as i know, the command mat2cell is used to break a big matrix into smaller cells that is why i m using this for the aforesaid purpose. i need to compare all the cells (obtained after breaking b, the big matrix, into smaller cells) with mat1. i know i m making some blunder but i hope now my query is clear to you.can you please guide me of some proper way to break a big matrix into smaller chunks and correlating it with the reference matrix?<br>
> <br>
> thanks,<br>
> areeba<br>
<br>
Hello,<br>
<br>
You should know that what matlab refers to as cell is not a "cell" as in a smaller component of the big matrix. Try this to see the difference :<br>
<br>
>a=[1,2;3,4];<br>
>b={1,2;3,4}<br>
>whos a b<br>
<br>
You can get you chunk of matrix by doing A(ii:ii+8,jj:jj+8).<br>
Regarding the other issue, I must subscribe to the other previous thoughts in this thread. Analyzing small pieces is not a good idea. If you do not overlay the small pads you can be sure to have errors and if you overlay them you are doing too many calculations. I'm suggesting you should reconsider your approach. <br>
<br>
Regards,<br>
Florin

Fri, 27 May 2011 21:38:04 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838295
areeba khan
"Jeff " <jea@gene.dot.com> wrote in message <iroh3k$io4$1@newscl01ah.mathworks.com>...<br>
> "areeba khan" wrote in message <iroa2l$pr5$1@newscl01ah.mathworks.com>...<br>
> > "Jeff " <jea@gene.dot.com> wrote in message <irmatm$gfc$1@newscl01ah.mathworks.com>...<br>
> > > grayimg = rgb2gray(imagein);<br>
> > > <br>
> > > padimg = padarray(grayimg, [3 4], 0, 'post'); %modify these values to make your image dimensions divisible by 9<br>
> > > <br>
> > > height = size(padimg,1); %height of full image<br>
> > > width = size(padimg,2); %width of full image<br>
> > > <br>
> > > n_width = 9;<br>
> > > m_height = 9;<br>
> > > <br>
> > > for x = 1:m_height:height<br>
> > > for y=1:n_width:width<br>
> > > image = bigmont(y:y+m_height1, x:x+n_width1);<br>
> > > imwrite(image,strcat(num2str(x),'^',num2str(y),'.jpg'),'jpg', 'Quality',80);<br>
> > > end<br>
> > > <br>
> > > end<br>
> > > <br>
> My apologies. I went through and renamed some of the variables to more generic names, and missed that one. Replace "bigmont" with "padimg".<br>
<br>
Jeff,<br>
thanks for the code..but its reducing the image rather then dividing it..secondly its giving an error<br>
<br>
??? Index exceeds matrix dimensions<br>
<br>
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..<br>
thanks

Fri, 27 May 2011 23:08:04 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838301
Jeff
"areeba khan" wrote in message <irp5js$htg$1@newscl01ah.mathworks.com>...<br>
> "Jeff " <jea@gene.dot.com> wrote in message <iroh3k$io4$1@newscl01ah.mathworks.com>...<br>
> > "areeba khan" wrote in message <iroa2l$pr5$1@newscl01ah.mathworks.com>...<br>
> > > "Jeff " <jea@gene.dot.com> wrote in message <irmatm$gfc$1@newscl01ah.mathworks.com>...<br>
> > > > grayimg = rgb2gray(imagein);<br>
> > > > <br>
> > > > padimg = padarray(grayimg, [3 4], 0, 'post'); %modify these values to make your image dimensions divisible by 9<br>
> > > > <br>
> > > > height = size(padimg,1); %height of full image<br>
> > > > width = size(padimg,2); %width of full image<br>
> > > > <br>
> > > > n_width = 9;<br>
> > > > m_height = 9;<br>
> > > > <br>
> > > > for x = 1:m_height:height<br>
> > > > for y=1:n_width:width<br>
> > > > image = bigmont(y:y+m_height1, x:x+n_width1);<br>
> > > > imwrite(image,strcat(num2str(x),'^',num2str(y),'.jpg'),'jpg', 'Quality',80);<br>
> > > > end<br>
> > > > <br>
> > > > end<br>
> > > > <br>
> > My apologies. I went through and renamed some of the variables to more generic names, and missed that one. Replace "bigmont" with "padimg".<br>
> <br>
> Jeff,<br>
> thanks for the code..but its reducing the image rather then dividing it..secondly its giving an error<br>
> <br>
> ??? Index exceeds matrix dimensions<br>
> <br>
> 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..<br>
> thanks<br>
<br>
The "Index exceeds matrix dimensions" is probably because you need to change the "3" and "4" in:<br>
padimg = padarray(grayimg, [3 4], 0, 'post');<br>
to give you an image with dimensions evenly divisible by 9. <br>
<br>
For example, you could make your image 963x1267 by using:<br>
padimg = padarray(grayimg, [3 7], 0, 'post');<br>
<br>
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: (<a href="http://www.mathworks.com/help/techdoc/matlab_prog/br04bw698.html#br1zng61">http://www.mathworks.com/help/techdoc/matlab_prog/br04bw698.html#br1zng61</a>). Does this make sense?

Sat, 28 May 2011 01:00:04 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838308
Roger Stafford
ImageAnalyst <imageanalyst@mailinator.com> wrote in message <19b3ec1eebf04b21bf3c6c3cddd59791@z13g2000yqg.googlegroups.com>...<br>
> Roger:<br>
> Wow, kind of tricky and unintuitive. Not sure I follow completely. I<br>
> didn't see any explanation in xcorr2's help about how to normalize<br>
> your input arrays before calling xcorr2, unless you're referring to<br>
> this terse entry:<br>
> "The normalized crosscorrelation of the (2,4) output element is<br>
> 585/sqrt(sum(dot(I1p,I1p))*sum(dot(I2,I2))) = 0.8070"<br>
> Is that what you did? Is that their "explanation"? I don't really<br>
> see from the above how that tells me to normalize my input arrays. If<br>
> that is what you need to do to fix up your inputs to get a spike at<br>
> the alignment spot, then I bet it will be overlooked by the vast<br>
> majority of people who will just blindly apply the correlation and<br>
> expect to see a spike at the "right" place. How would you fix up my<br>
> code to give a spike (value of 1.000) at the proper 4,3 location?<br>
> ImageAnalyst<br>
          <br>
Hello ImageAnalyst and Areeba.<br>
<br>
I agree with you, ImageAnalyst, that the writeup on 'xcorr2' leaves much to be desired. Among other things the equation where they define C(i,j) has the indices going the wrong way. As i and j increase, they are actually moving backward in B, contrary to their claim in expression, B(m+i,n+j). Worst of all, they don't seem to provide for normalization even though they describe it. It isn't a matter of normalizing the input to 'xcorr2'. Normalization ought to be performed as an integral part of the processing within 'xcorr2', because the normalization requirements change with every shift in relative location between the two input arrays. In its absence the method below is a way of accomplishing this normalization even though it is rather cumbersome. It would be much more efficient if it were provided for as an option.<br>
<br>
Nevertheless I feel that 'xcorr2' could be very useful for your purposes, Areeba. Using your original notation, if 'b' is the adjusted 1280 by 960 image and 'mat1' is the reference matrix, you can do this:<br>
<br>
C = xcorr2(b,mat1) ./ ...<br>
sqrt(xcorr2(b.^2,ones(size(mat1))).*xcorr2(ones(size(b)),mat1.^2));<br>
C = C(9:1280,9:960);<br>
<br>
This finds the correlations, which will be numbers between +1 and 1, between 'mat1' and every 9 by 9 block within the array 'b'. The second operation removes any correlations in which 'mat1' extends out past the edges of 'b' where padded zeros were added. The documentation designates these remaining correlations as the "valid" ones. What you will be looking for are correlations that are fairly close to +1 among these.<br>
<br>
There are necessarily fewer elements in C than in 'b'. C(1,1) would be the correlation of the 9 by 9 'mat1' centered over the (5,5) element in 'b'. At the other extreme C(1272,952) is centered over (1276,956) in 'b'.<br>
<br>
I claim there is an advantage in this method in that every 9 by 9 block is tested, not just a particular random partitioning of the image. If the cancer pattern you are trying to match happens to fall half way between partitioned blocks or at the corners of four of them, you could easily miss it. In my opinion it is prudent to test every possible 9 by 9 block. Of course, that does mean a much lengthier processing time than would be spent with fewer blocks.<br>
<br>
Roger Stafford

Sat, 28 May 2011 01:49:04 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838312
ImageAnalyst
On May 27, 9:00 pm, "Roger Stafford"<br>
<ellieandrogerxy...@mindspring.com.invalid> wrote:<br>
[snip]<br>
> the normalization requirements change with every shift in relative location between the two input arrays....[snip] Using your original notation, if 'b' is the adjusted 1280 by 960 image and 'mat1' is the reference matrix, you can do this:<br>
><br>
> C = xcorr2(b,mat1) ./ ...<br>
> sqrt(xcorr2(b.^2,ones(size(mat1))).*xcorr2(ones(size(b)),mat1.^2));<br>
[snip]<br>
<br>
> Roger Stafford<br>
<br>
Roger:<br>
I can't say that I followed how your formula allowed the arrays to<br>
change normalization at every shift location, so I just decided to try<br>
it with my data . . . and it worked (well mostly).<br>
<br>
% Define image 1<br>
I1 = [1 2 3 100 100<br>
11 5 8 100 100<br>
4 6 13 100 100<br>
10 12 15 100 100<br>
100 100 100 100 100]<br>
<br>
%Define image 2 = I1(2:4, 1:3)<br>
I2 = [11 5 8<br>
4 6 13<br>
10 12 15]<br>
<br>
% First do the regular MATLAB cross correlation.<br>
c = xcorr2(I1, I2)<br>
<br>
% Now use Roger's formula for normalized cross correlation:<br>
b=I1;<br>
mat1 = I2;<br>
C = xcorr2(b,mat1) ./ ...<br>
sqrt(xcorr2(b.^2,ones(size(mat1))).* ...<br>
xcorr2(ones(size(b)),mat1.^2))<br>
<br>
% I2 is aligned with I1 at row 4, column 3<br>
% of the cross correlation matrix.<br>
% Remember the cross correlation matrix is bigger than either one.<br>
% Let's see if the max is really at row 4, column 3,<br>
% where you think it should be.<br>
[maxRow maxCol] = find(C == max(C(:)));<br>
<br>
for k = 1:length(maxRow)<br>
fprintf('Found a max at row=%d, col=%d\n',...<br>
maxRow(k), maxCol(k));<br>
end<br>
<br>
Results:<br>
<br>
I1 =<br>
<br>
1 2 3 100 100<br>
11 5 8 100 100<br>
4 6 13 100 100<br>
10 12 15 100 100<br>
100 100 100 100 100<br>
<br>
<br>
I2 =<br>
<br>
11 5 8<br>
4 6 13<br>
10 12 15<br>
<br>
<br>
c =<br>
<br>
15 42 79 1556 2730<br>
2200 1000<br>
178 239 345 2972 4692<br>
3200 1400<br>
211 290 530 3921 6095<br>
4800 2500<br>
290 497 900 4097 6190<br>
4800 2500<br>
1662 2984 4185 6069 7103<br>
4800 2500<br>
1380 2046 2590 3307 3765<br>
2600 1500<br>
800 1300 2400 2400 2400<br>
1600 1100<br>
<br>
<br>
C =<br>
<br>
1.0000 0.9778 0.9749 0.7180 0.8912 0.9959 1.0000<br>
0.8119 0.8118 0.8775 0.7980 0.8923 0.9300 0.9191<br>
0.8393 0.7905 0.8375 0.7508 0.8278 0.9321 0.9376<br>
0.8802 0.9181 1.0000 0.7799 0.8392 0.9321 0.9376<br>
0.7721 0.8135 0.7963 0.8996 0.8924 0.9321 0.9376<br>
0.8996 0.8387 0.7147 0.7928 0.8092 0.9239 0.9062<br>
1.0000 0.9744 0.9562 0.9562 0.9562 0.9363 1.0000<br>
<br>
Found a max at row=1, col=1<br>
Found a max at row=7, col=1<br>
Found a max at row=4, col=3<br>
Found a max at row=1, col=7<br>
Found a max at row=7, col=7<br>
<br>
So it does find the max at row 4, column 3 like it "is supposed to"<br>
but it seems to get a 1.0000 at every corner also. Not sure why that<br>
happens (off the top of my head), but if it's always at the 4 corners,<br>
you could make sure to always just ignore those positions, for example<br>
by cropping them off, which is what you did.<br>
<br>
I think your solution is not all that obvious so perhaps you should<br>
add it to the FAQ because I think a lot of people are puzzled when the<br>
cross correlation does not produce the expected "spike" at the<br>
expected location.<br>
<br>
I agree with you that the documentation should be improved and that<br>
this type of correlation should be made an option.<br>
ImageAnalyst

Sat, 28 May 2011 03:14:04 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838320
Roger Stafford
ImageAnalyst <imageanalyst@mailinator.com> wrote in message <fd737d21b2f148c58c89299e0a76492b@b42g2000yqi.googlegroups.com>...<br>
> Roger:<br>
> I can't say that I followed how your formula allowed the arrays to<br>
> change normalization at every shift location, so I just decided to try<br>
> it with my data . . . and it worked (well mostly).<br>
> ..........<br>
> So it does find the max at row 4, column 3 like it "is supposed to"<br>
> but it seems to get a 1.0000 at every corner also. Not sure why that<br>
> happens (off the top of my head), but if it's always at the 4 corners,<br>
> you could make sure to always just ignore those positions, for example<br>
> by cropping them off, which is what you did.<br>
> <br>
> I think your solution is not all that obvious so perhaps you should<br>
> add it to the FAQ because I think a lot of people are puzzled when the<br>
> cross correlation does not produce the expected "spike" at the<br>
> expected location.<br>
> <br>
> I agree with you that the documentation should be improved and that<br>
> this type of correlation should be made an option.<br>
> ImageAnalyst<br>
           <br>
In searching for the "spike" you speak of, ImageAnalyst, you shouldn't include the part of C that has been influenced by the padding with zeros off the edges. In the case of your I1 and I2, the "valid" (as Mathworks designated them) correlations are in the central portion:<br>
<br>
C(3:5,3:5) =<br>
<br>
0.8375 0.7508 0.8278<br>
1.0000 0.7799 0.8392<br>
0.7963 0.8996 0.8924<br>
<br>
These correspond to the nine possible ways of fitting your 3 x 3 I2 array entirely inside the 5 x 5 I1 array. As you see, in this region the match at C(4,3) dominates everything else.<br>
<br>
The 1's at the corners of the full C matrix are inevitable, since a single pair of numbers is being compared for correlation and since they are indeed "proportional" to each other, the correlation is 1 (or 1.) That is, you get a*b/sqrt(a^2*b^2) which always gives +1 or 1. This is an indication of how those border areas are not of as much significance as those unaffected by zero padding. The farther out they are, the worse they get.<br>
<br>
It's a little hard to explain the theory of that formula I gave you, but I'll try. If you recall, without any normalization you get the sum of products of two series of numbers, a1, a2, ..., an and b1, b2, ..., bn as:<br>
<br>
a1*b1 + a2*b2 + ... + an*bn<br>
<br>
Of course these numbers change at every step of the correlation computation. To normalize this sum of products you must divide it by<br>
<br>
sqrt( (a1^2 + a2^2 + ... + an^2) * (b1^2 + b2^2 + ... + bn^2) )<br>
<br>
and these quantities will also be changing at every step. Notice that each of the factors of sums inside the square root can itself be looked upon as another unnormalized correlation:<br>
<br>
(a1^2)*1 + (a2^2)*1 + ... + (an^2)*1<br>
<br>
That is, we need the unnormalized correlation between a1^2, a2^1, ,,, an^2 and 1, 1, ..., 1. The same applies to the b's.<br>
<br>
So the strategy is to run three 'xcorr2' correlations in parallel, so to speak. After obtaining them, all we do is take the elementbyelement products, quotients, and square roots to get the normalized correlations we desire. It's unsightly but it works.<br>
<br>
It can surely be simplified. In a case like yours when one array is smaller in both sizes than the other and when we chop off the correlation portion influenced by zero padding, then one of these above sums of products inside the square root remains constant, so actually the number of 'xcorr2' calls then needed could be pared down to only two with careful programming.<br>
<br>
Roger Stafford

Sat, 28 May 2011 19:52:04 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838350
Roger Stafford
"areeba khan" wrote in message <irm4h1$jke$1@newscl01ah.mathworks.com>...<br>
> i am working on a project detection of skin cancer using image processing..i have found a reference matrix of 9by9 of tumourous cell now through looping i want 2 compare this reference matrix with the image... ............<br>
           <br>
To ImageAnalyst and Areeba: I just ran across a matlab function which computes a normalized cross correlation of twodimensional arrays. It is called 'normxcorr2' and is to be found in the Image Processing Toolbox. The documentation can be read at:<br>
<br>
<a href="http://www.mathworks.com/help/toolbox/images/ref/normxcorr2.html">http://www.mathworks.com/help/toolbox/images/ref/normxcorr2.html</a><br>
<br>
This normalization differs from the one I have described in this thread in that it also subtracts mean values in each frame before computing the correlation. However its values are similarly bounded by 1 and +1. You might like to experiment with this function, Areeba.<br>
<br>
I have one more observation to make about your problem, Areeba. All these various kinds of correlation measurements are in my opinion very crude methods of making pattern comparisons.<br>
<br>
You are apparently trying to do automatic pattern recognition of small cancer spots in nine by nine frames of grey level pixels. In my opinion the only proper way to achieve such an ambitious goal as this is to develop very complex comparison logic, probably by means of neural network learning procedures which can be implemented in the neural network toolbox.<br>
<br>
However doing this requires far more than a single, simple template to compare images with. It needs an entire extended learning period with a large and representative sample of how nine by nine cancer spots would look under a variety of conditions, locations, orientations, and contrast levels. Most particularly the learning process must be exposed to the full variety that exists among different kinds of cancer patterns themselves.<br>
<br>
Roger Stafford

Sat, 28 May 2011 22:44:50 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838351
ImageAnalyst
On May 28, 3:52 pm, "Roger Stafford"<br>
<ellieandrogerxy...@mindspring.com.invalid> wrote:<br>
> To ImageAnalyst and Areeba: I just ran across a matlab function which computes a normalized cross correlation of twodimensional arrays. It is called 'normxcorr2' and is to be found in the Image Processing Toolbox. The documentation can be read at:<br>
><br>
> <a href="http://www.mathworks.com/help/toolbox/images/ref/normxcorr2.html">http://www.mathworks.com/help/toolbox/images/ref/normxcorr2.html</a><br>
<br>
> Roger Stafford<br>
<br>
<br>
Yes, you're right. Good find! That will be handy to know. I never<br>
noticed it because it's not a "See Also" under xcorr2, possibly<br>
because they're in different toolboxes (Signal vs. Image). But when<br>
you type "correlation" into the help, the normxcorr2 function doesn't<br>
show up until the 9th one down (R2011a), and it's not even mentioned<br>
at all when you go to the top entry on correlation.<br>
<br>
There is actually quite a nice demo using it in there: "Registering an<br>
Image Using Normalized CrossCorrelation" which does what I think<br>
areeba wants to do in early explorations. However I very much agree<br>
with Roger that this method ultimately will not be very good at<br>
detecting cancerous locations. It may work for a few locations where<br>
the cancer pretty much exactly looks like the template, but won't be<br>
robust enough in general to be a useful algorithm in the realworld<br>
practical sense. However, if it's just for limited demo purposes,<br>
like a student homework project, then it may fit the bill as long as<br>
you list potential disadvantages and limitations of it in the<br>
conclusions/summary.

Sun, 29 May 2011 12:09:05 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838394
areeba khan
"Jeff " <jea@gene.dot.com><br>
> > > > > grayimg = rgb2gray(imagein);<br>
> > > > > <br>
> > > > > padimg = padarray(grayimg, [3 4], 0, 'post'); %modify these values to make your image dimensions divisible by 9<br>
> > > > > <br>
> > > > > height = size(padimg,1); %height of full image<br>
> > > > > width = size(padimg,2); %width of full image<br>
> > > > > <br>
> > > > > n_width = 9;<br>
> > > > > m_height = 9;<br>
> > > > > <br>
> > > > > for x = 1:m_height:height<br>
> > > > > for y=1:n_width:width<br>
> > > > > image = bigmont(y:y+m_height1, x:x+n_width1);<br>
> > > > > imwrite(image,strcat(num2str(x),'^',num2str(y),'.jpg'),'jpg', 'Quality',80);<br>
> > > > > end<br>
> > > > > <br>
> > > > > end<br>
<br>
> The "Index exceeds matrix dimensions" is probably because you need to change the "3" and "4" in:<br>
> padimg = padarray(grayimg, [3 4], 0, 'post');<br>
> to give you an image with dimensions evenly divisible by 9. <br>
> <br>
> For example, you could make your image 963x1267 by using:<br>
> padimg = padarray(grayimg, [3 7], 0, 'post');<br>
> <br>
> 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: (<a href="http://www.mathworks.com/help/techdoc/matlab_prog/br04bw698.html#br1zng61">http://www.mathworks.com/help/techdoc/matlab_prog/br04bw698.html#br1zng61</a>). Does this make sense?<br>
<br>
Jeff,<br>
i had done the same way as you are refering to i.e. i had changed 4 with 7 in:<br>
padimg line...and got the error i told you (index exceed matrix dimension)...<br>
and thank you..now i got about the variable image point..<br>
<br>
do i need to reduce my image size? if yes then how?

Sun, 29 May 2011 13:32:05 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838397
ImageAnalyst
On May 29, 8:09 am, "areeba khan" <arybak...@hotmail.com> wrote:<br>
> do i need to reduce my image size? if yes then how?<br>
<br>
No. In fact, Roger and I don't know why you're continuing down this<br>
path of processing subimages in steps of 9 when both he and I<br>
recommended against it. Can you explain why that would be better than<br>
sliding over one pixel at a time? What happens if the region you're<br>
looking for is half way on one 9x9 chunk and half way on its neighbor?

Mon, 30 May 2011 15:56:04 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838514
Jeff
"areeba khan" wrote in message <irtd11$267$1@newscl01ah.mathworks.com>...<br>
> "Jeff " <jea@gene.dot.com><br>
> > > > > > grayimg = rgb2gray(imagein);<br>
> > > > > > <br>
> > > > > > padimg = padarray(grayimg, [3 4], 0, 'post'); %modify these values to make your image dimensions divisible by 9<br>
> > > > > > <br>
> > > > > > height = size(padimg,1); %height of full image<br>
> > > > > > width = size(padimg,2); %width of full image<br>
> > > > > > <br>
> > > > > > n_width = 9;<br>
> > > > > > m_height = 9;<br>
> > > > > > <br>
> > > > > > for x = 1:m_height:height<br>
> > > > > > for y=1:n_width:width<br>
> > > > > > image = bigmont(y:y+m_height1, x:x+n_width1);<br>
> > > > > > imwrite(image,strcat(num2str(x),'^',num2str(y),'.jpg'),'jpg', 'Quality',80);<br>
> > > > > > end<br>
> > > > > > <br>
> > > > > > end<br>
> <br>
> > The "Index exceeds matrix dimensions" is probably because you need to change the "3" and "4" in:<br>
> > padimg = padarray(grayimg, [3 4], 0, 'post');<br>
> > to give you an image with dimensions evenly divisible by 9. <br>
> > <br>
> > For example, you could make your image 963x1267 by using:<br>
> > padimg = padarray(grayimg, [3 7], 0, 'post');<br>
> > <br>
> > 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: (<a href="http://www.mathworks.com/help/techdoc/matlab_prog/br04bw698.html#br1zng61">http://www.mathworks.com/help/techdoc/matlab_prog/br04bw698.html#br1zng61</a>). Does this make sense?<br>
> <br>
> Jeff,<br>
> i had done the same way as you are refering to i.e. i had changed 4 with 7 in:<br>
> padimg line...and got the error i told you (index exceed matrix dimension)...<br>
> and thank you..now i got about the variable image point..<br>
> <br>
> do i need to reduce my image size? if yes then how?<br>
<br>
Then you'll need to do some troubleshooting. Make sure the image PADARRAY is being changed to the correct dimensions. If it is, then check at what value x and y are when you get the error.<br>
<br>
OR....<br>
<br>
You could change your approach so that you don't have to worry about getting 9x9 image fragments, and will probably give you a more robust result. The approach outlined by ImageAnalyst and Roger (again, outlined here: <a href="http://www.mathworks.com/products/demos/image/cross_correlation/imreg.html">http://www.mathworks.com/products/demos/image/cross_correlation/imreg.html</a> ) may be a bit more complex, conceptually, but would be well worth the time to try.

Mon, 30 May 2011 19:57:04 +0000
Re: divide 1280by960 image into 9by9
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308359#838545
areeba khan
ImageAnalyst <imageanalyst@mailinator.com> wrote in message <8669ccdd00e341e991f8038617fdf66d@g12g2000yqd.googlegroups.com>...<br>
> On May 29, 8:09 am, "areeba khan" <arybak...@hotmail.com> wrote:<br>
> > do i need to reduce my image size? if yes then how?<br>
> <br>
> No. In fact, Roger and I don't know why you're continuing down this<br>
> path of processing subimages in steps of 9 when both he and I<br>
> recommended against it. Can you explain why that would be better than<br>
> sliding over one pixel at a time? What happens if the region you're<br>
> looking for is half way on one 9x9 chunk and half way on its neighbor?<br>
<br>
Image Analyst,<br>
i had already done this.. though this approach is working but it was very much time consuming (perhaps the size of image is large)...that is why i am a bit hesitant towards it..i don't know but somewhere i have in my mind (i may be wrong though) that the 9x9 method could be a bit fast...<br>
I know your and Roger's point of loosing the clues is really valid.. i can continue with this approach..as it is working but i also need to think of some other alternative as to make it a bit fast...<br>
<br>
Regards,<br>
Areeba