Azzera filtri
Azzera filtri

rgb_sum for mutiple images

1 visualizzazione (ultimi 30 giorni)
babli
babli il 13 Feb 2015
Commentato: babli il 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..?

Risposta accettata

Michael Haderlein
Michael Haderlein il 13 Feb 2015
Modificato: Michael Haderlein il 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 Commenti
babli
babli il 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 il 13 Feb 2015
it still giving error: Attempted to access rgb_sum(2); index out of bounds because numel(rgb_sum)=1.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by