can any one provide me the code for dividing the image 306x204 into blocks of size i,e windows of size 17x17

i want to know the code for dividing the image into blocks or windows of size 17x17

1 Comment

im = rand(306,204);
for k=1:12*18
for i=1:306/18
for j=1:204/12
newim(i,j,k)=im(i*18,j*12);
end
end
end
Does this clear your query? MATLABhelper.com

Sign in to comment.

 Accepted Answer

im=rand(306,204)
[n,m]=size(im)
[ii,jj]=ndgrid(1:17:n,1:17,m)
out=arrayfun(@(x,y) im(x:x+16,y:y+16),ii,jj,'un',0)

7 Comments

clear all
clc
close all
I=(imread('wm.gif'));
I=imresize(I,[306 204]);
I=I/max(max(I));
I=double(I);
[m n]=size(I);
% I=magic(4);
% [m n]=size(I);
for i=1:18
for j=1:12
% num=2i+j-2;
filter_gradient = fspecial('sobel');
%to get x gradient
if((i-1>0)&&(j-1)>0)
gx((i-1)*17:(i)*17,(j-1)*17:(j)*17) = filter2(filter_gradient,I((i-1)*17:(i)*17,(j-1)*17:(j)*17));
%to get y gradient
filter_gradient = transpose(filter_gradient);
gy((i-1)*17:(i)*17,(j-1)*17:(j)*17)= filter2(filter_gradient,I((i-1)*17:(i)*17,(j-1)*17:(j)*17));
end
end
end
figure;imshow(gx)
[g1 g2]=imgradientxy(I,'sobel')
figure;imshow(g1)
%%ridge orientation
gxy(1:m,1:n)=0;gxx(1:m,1:n)=0;gyy(1:m,1:n)=0;
for i=9:m-9
for j=9:n-9
for i1=-8:+8
for j1=-8:+8
gxy(i,j)=gxy(i,j)+((gx(i+i1,j+j1)).*(gy(i+i1,j+j1)));
gxx(i,j)=gxx(i,j)+gx(i+i1,j+j1).^2;
gyy(i,j)=gyy(i,j)+gy(i+i1,j+j1).^2;
end
end
Q(i,j)=pi/2+0.5*(atan2((2*gxy(i,j)),((gxx(i,j)-gyy(i,j)))));
end
end
so far i have done upto this , i have to calculate ridge orientation and gradients using block wise can you help in writing the code for and am not sure whether mine is correct or not
yeah actually my whole process goes on dividing the blocks and then proceeding further and the code which you have given it was showing 18x17 but i want 17x17
im=rand(306,204)
[n,m]=size(im)
n1=n/17
m1=m/17
[ii,jj]=ndgrid(1:n1:n,1:m1:m)
out=arrayfun(@(x,y) im(x:x+n1-1,y:y+m1-1),ii,jj,'un',0)
size(out)
What does "proceeding further" mean, and why is blocproc() - the built-in function meant for this kind of thing - no good? blockproc will both split up, AND process each block with your custom code, all in one single line of code.
Kumar, if you have Image Processing Toolbox you can use blockproc function
Example, if you want to calculate the mean of each block
im=rand(306,204)
[n,m]=size(im)
n1=n/17
m1=m/17
out=blockproc(im,[n1,m1],@(x) mean(mean(x.data)))
sir can you tell me the code with out using this inbuilt functions (blockproc,arrayfun).. and actaully i want to calculate the gradient of each pixel in each block

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!