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.

2 次查看(过去 30 天)
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..
  5 个评论
Image Analyst
Image Analyst 2017-2-8
What's your definition of energy? If you go back to first principles, and work out the units, you'll see that gray level has units of energy. So all you need to do is to take the moving mean, like in the attached demos.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2011-11-4
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.
  31 个评论
Soumya
Soumya 2011-12-9
sir,
Acoording to ur guidance i have solved many of my problems.thanks for ur guidance and instructions sir.At the last moment i am facing a small problem,but I'm not able to find wat's wrong can u help me .code----->
[r c dim]=size(SeamImg);%%128 128
[SVrow SVcol]=size(SeamVector);%%128 128
for i=1:SVcol
for k=1:dim
for j=1:r
if SeamVector(j,i)==1
cut(j,:,k)=SeamImg(j,2:c,k);
elseif SeamVector(j,i)==c
cut(j,:,k)=SeamImg(j,1:c-1,k);
else
cut(j,:,k)=[SeamImg(j,1:SeamVector(j,i)-1,k) SeamImg(j,SeamVector(j,i)+1:c,k)];
end
end
end
end
SeamImg=cut;
clear cut
figure
imshow(SeamImg)
%%%error-->
Subscripted assignment dimension mismatch.
Error in ==> blocksfinal at 186
cut(j,:,k)=[SeamImg(j,1:SeamVector(j,i)-1,k) SeamImg(j,SeamVector(j,i)+1:c,k)];
I'm waiting for ur valuable instructions......
Walter Roberson
Walter Roberson 2011-12-9
That error could occur if you had initialized the cut() array to an incompatible size. You do not _show_ any initialization for cut(), but we don't know that you did not do any in code you did not show us.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by