MATLAB: I had divided an image into blocks where each block has 8*8 pixels .Now i want to find the energy of each block,for that i have to consider the energy of each pixels in a block and the calculations are given in the code below.

After making the calculation for each block i have to show the enery map of the image that is being divided into blocks ,but i am not geting it .Can you plz help me .Actualy i am trying to do block based seam carving
x=imread('cameraman.tif');
y=double(x);
[r c]=size(y);
bs=8; %size of each block
nob=(r/bs)*(c/bs);%number of blocks
kk=0;
for i=1:(r/bs)
for j=1:(c/bs)
Block(:,:,kk+j)=y((bs*(i-1)+1:bs*(i-1)+bs),(bs*(j-1)+1:bs*(j-1)+bs));
%block creation
%ENERGY CALCULATION PER BLOCK
for q=1:bs
for p=1:bs
if((q-1==0)&&(p-1==0))
a=Block(q,p,kk+j);
b=0;
n=a-b;
c=Block(q,p,kk+j);
d=0;
m=c-d;
elseif((q-1==0)&&(p-1~=0))
n=y(q:q,p)-y(q:q,p-1);
a=Block(q,p,kk+j);
b=0;
m=a-b;
elseif((q-1~=0)&&(p-1==0))
a=Block(q,p,kk+j);
b=0;
n=a-b;
m=y(q:q,p)-y(q-1:q-1,p);
else
n=y(q:q,p)-y(q:q,p-1);
m=y(q:q,p)-y(q-1:q-1,p);
end
s=n+m ;%
en=s/nob;%Here the calculation for energy for block is being done.
imshow(en)
% Here i want to show the energy map for the entier blocks but unfortunatly i am geting only a single spot.
end
end
end
kk=kk+(r/bs);
end
%%%%%%%%%% I GOT UR ANSWER BUT I'M NOT GETING THE CORRECT OUTPUT ,CAN U PLZZZZ HELP ME OUT.THE PBLM THAT I FACED IS PUT AS A COMMENT TO UR ANSWER PLZ CHECK IT..

Best Answer

Is "en" an image? I don't see any indices being used when you set values for it. It looks to me like it is a scalar so that would show up as a single point.
Maybe you want this
en(p, q)=s/nob;
and then after the q and p loops have finished (when you'll have the complete image), do the imshow.