rgb_sum for mutiple images

1 回表示 (過去 30 日間)
babli
babli 2015 年 2 月 13 日
コメント済み: babli 2015 年 2 月 13 日
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..?

採用された回答

Michael Haderlein
Michael Haderlein 2015 年 2 月 13 日
編集済み: Michael Haderlein 2015 年 2 月 13 日
[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 件のコメント
babli
babli 2015 年 2 月 13 日
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 2015 年 2 月 13 日
it still giving error: Attempted to access rgb_sum(2); index out of bounds because numel(rgb_sum)=1.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by