From: Nghia Le on
Hi, I am new to medical imaging analysis and matlab. Here is what I am trying to solve, hope you can provide me some guidance:
I am trying to segment an image into smaller blocks and analyze data those blocks individually. For example, I have a 20x20 image (grayscale) and I want to segment into four blocks and form a 3-dimensional matrix 5x5x16 that I call 'A' by using for loop and here is my test code:

I=magic(20);
for m=1:4;
for n=1:4;
vl=(m-1)*5+1;
vh=(m-1)*5+5;
hl=(n-1)*5+1;
hh=(n-1)*5+5;

A(:,:,:)=I(vl:vh,hl:hh)
end
end

Here is my problem, I cannot get A to define in term of m and n. For example if I want to view block A(m=1 and n=3) it would show up I(1:5,11:15). I been searching for the correct code two days and yet to find the solution. Hope you can provide some guidance. Thank you in advanced.
From: ImageAnalyst on
You should consider using the function blockproc() which is meant for
exactly this kind of situation.
From: Nghia Le on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <c3d1c820-00b0-4ac3-ac1f-43bdf8c4628d(a)v16g2000vba.googlegroups.com>...
> You should consider using the function blockproc() which is meant for
> exactly this kind of situation.

I tried your advice, but can't get it to work. The only problem in my previous code is that I do not know to index matrix A. For example, 'n' in A(:,:,n). Thank you for your response.
From: Ashish Uthama on
On Thu, 15 Apr 2010 22:59:04 -0300, Nghia Le <nghiatle(a)gmail.com> wrote:

> Hi, I am new to medical imaging analysis and matlab. Here is what I am
> trying to solve, hope you can provide me some guidance:
> I am trying to segment an image into smaller blocks and analyze data
> those blocks individually. For example, I have a 20x20 image
> (grayscale) and I want to segment into four blocks and form a
> 3-dimensional matrix 5x5x16 that I call 'A' by using for loop and here
> is my test code:
>
> I=magic(20);
> for m=1:4;
> for n=1:4;
> vl=(m-1)*5+1;
> vh=(m-1)*5+5;
> hl=(n-1)*5+1;
> hh=(n-1)*5+5;
>
> A(:,:,:)=I(vl:vh,hl:hh)
> end
> end
>
> Here is my problem, I cannot get A to define in term of m and n. For
> example if I want to view block A(m=1 and n=3) it would show up
> I(1:5,11:15). I been searching for the correct code two days and yet to
> find the solution. Hope you can provide some guidance. Thank you in
> advanced.

I am curious to know why you would want to dice your image this way?

add another outer FOR loop

for thirdInd = 1:16
.....
A(:,:,thirdInd) = I(vl:vh,hl:hh)
.....
end
From: Nghia Le on
Hi, what I am trying to do is to identify the tumor, normal, or background region by using the wavelet transform on each block to obtain mean and std for each component. After that I will form a ID matrix and use classify function for computer learning process.

Concerning your suggestion, I did try the third loop many times and trials, but the output for all A(:,:1), A(:,:,2), A(:,:,3)... is the identical matrix.

I am sure there is a simple fix for this, but I do not know how to do it. I will keep posted.


"Ashish Uthama" <first.last(a)mathworks.com> wrote in message <op.va9gfioua5ziv5(a)uthamaa.dhcp.mathworks.com>...
> On Thu, 15 Apr 2010 22:59:04 -0300, Nghia Le <nghiatle(a)gmail.com> wrote:
>
> > Hi, I am new to medical imaging analysis and matlab. Here is what I am
> > trying to solve, hope you can provide me some guidance:
> > I am trying to segment an image into smaller blocks and analyze data
> > those blocks individually. For example, I have a 20x20 image
> > (grayscale) and I want to segment into four blocks and form a
> > 3-dimensional matrix 5x5x16 that I call 'A' by using for loop and here
> > is my test code:
> >
> > I=magic(20);
> > for m=1:4;
> > for n=1:4;
> > vl=(m-1)*5+1;
> > vh=(m-1)*5+5;
> > hl=(n-1)*5+1;
> > hh=(n-1)*5+5;
> >
> > A(:,:,:)=I(vl:vh,hl:hh)
> > end
> > end
> >
> > Here is my problem, I cannot get A to define in term of m and n. For
> > example if I want to view block A(m=1 and n=3) it would show up
> > I(1:5,11:15). I been searching for the correct code two days and yet to
> > find the solution. Hope you can provide some guidance. Thank you in
> > advanced.
>
> I am curious to know why you would want to dice your image this way?
>
> add another outer FOR loop
>
> for thirdInd = 1:16
> ....
> A(:,:,thirdInd) = I(vl:vh,hl:hh)
> ....
> end