rgb_sum for mutiple images
5 views (last 30 days)
Show older comments
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..?
0 Comments
Accepted Answer
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);
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox 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!