Samah Ahmed
Samah Ahmed

Reputation: 419

How I can find Mean Absolute Deviation for image by matlab

If I have image with this dimension 240x180 and I want to use Matlab to find Mean Absolute Deviation (MAD) for each sub-image ( 20x20) from the original image so I must extract 108 results at the end , I know the concepts of MAD by finding mean for each 20x20 sub-pixel then find the summation of the absolute value of the difference between each pixel and calculated mean.

I started to make something to divide image ( 240x180) to the sub-image with this dim ( 20x20) and I must have 108 sub-image but the result only contain 84 block I don't know why , you can look to the following code:

>> I = imread('myimage-path')
>> %the size of image 180x240
>> [r,c] = size(I);
>> bs = 20; % size of block
>> nsb = (r/bs) * (c/bs); % total number of block ( 108 block )
>> %Dividong the image into 20x20 block 
>> kk=0;
>> for i=1:(r/bs)
  for j=1:(c/bs)
    Block(:,:,kk+j)=I((bs*(i-1)+1:bs*(i-1)+bs),(bs*(j-1)+1:bs*   (j-1)+bs));
  end
  kk=kk+(r/bs);
  end

Then I defined empty array to store all 108 blocks at this array to complete my works on these blocks

>> allBlocks = [[],[],[]]
>> for h=1:84
allBlocks(:,:,h) = Block(:,:,h);
end

>> size(allBlocks)
>> % result 20 20 84 

Upvotes: 0

Views: 794

Answers (3)

Haroon Rasheed
Haroon Rasheed

Reputation: 5

I think When Your are dividing in the second loop kk=kk+(r/bs) (r/bs) gives a rounded value for some r and bsand hence not adding up the value of k the way it should

Upvotes: 0

Haroon Rasheed
Haroon Rasheed

Reputation: 5

look at this Problem in this manner!
1. Create a function MAD(takes in a iamge)
2. formulate 2 Loops that will pass windows(or Sub-Images or Templates) to your function. You can use : operator to give the range for your Sub Image.
3. You can Formulate a 3-D array to store you output with a dimension of 20x20X180.
4. And Good Luck!!
Take Care!!

Upvotes: 0

Alaa Khaled
Alaa Khaled

Reputation: 311

May be you can use Distinct block processing functions in this case

Upvotes: 0

Related Questions