rgb_sum for mutiple images

3 views (last 30 days)
babli
babli on 13 Feb 2015
Commented: babli on 13 Feb 2015
i ve a code for calculating rgb_sum value of a region in an image . now i want to run this for number of images but its giving error. here is the code for one image.
I=imread('C:\Users\ASUS\Desktop\ref_LB\g20.tif');
I=double(I);
rgb_sum=0;
[c r]=imfindcircles(I,[10 30]); c=round(c);
c1=c(1,2);
c2=c(1,1);
for i=-5:5;
for j=-5:5;
rgb_sum=rgb_sum+I(c1+i,c2+j);
end
end
its working properly for single image but when im trying it for series of images like here the code for multiple images-
for i=1:20;
file_name=strcat('C:\Users\ASUS\Desktop\ref_LB\g',num2str(i),'.tif');
I=imread(file_name);
I=double(I);
rgb_sum=0;
[c(i) r]=imfindcircles(I,[10 30]);
c=round(c);
c1=c(1,2);
c2=c(1,1);
for k=-5:5;
for j=-5:5;
rgb_sum(i)=rgb_sum+I(c1+k,c2+j);
end
end
end
its giving error; In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in reftest (line 11) [c(i) r]=imfindcircles(I,[10 30]); same for rgb_sum(i).
how to get them all in a single matrix . can anybody help me please..?

Accepted Answer

Michael Haderlein
Michael Haderlein on 13 Feb 2015
Edited: Michael Haderlein on 13 Feb 2015
[c(i) r]=imfindcircles(I,[10 30]);
Do you need the c of every image in the end? Or will you need it only temporarily in the loop? If you need it only inside the loop, change it to
[c r]=imfindcircles(I,[10 30]);
Otherwise, you have to index c with
[c(:,:,i),r]
as it is a matrix.
In any case, in this line
rgb_sum(i)=rgb_sum+I(c1+k,c2+j);
you need to write
rgb_sum(i)=rgb_sum(i)+I(c1+k,c2+j);
  2 Comments
babli
babli on 13 Feb 2015
no i don't need the value of c at the end..bt as it will change for every image means in the outer loop of i=1:10 it ve written c(i)..
babli
babli on 13 Feb 2015
it still giving error: Attempted to access rgb_sum(2); index out of bounds because numel(rgb_sum)=1.

Sign in to comment.

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!