efficient use of extracting mean over segments
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello, I have image (Iseg) where i have number of segments. Each segments is represented by unique number in Iseg. The segments are around (50000). I have another image(Idata) which is same size that of Iseg. For every segment in Iseq i want to extract mean value of segments from Idata.
Rightnow i am using like this
NumRegion = max(max(Iseg));
mean_magnitude = zeros(size(Iseg));
for i=1:NumRegion
[iIndList] = find(Iseg == i);
mean_magnitude(iIndList) = mean(Idata(iIndList));
end
It works fine, but the problem is that it takes a long time. about 10 mins in my machine. Is there a effecient way to do it.
댓글 수: 3
Image Analyst
2013년 2월 22일
편집: Image Analyst
2013년 2월 23일
I'm not sure either. Is a "segment" a blob in a binary image? And he wants the mean gray level of a gray level image for each blob region? Sounds like Iseg is a "labeled" image like you'd get from bwlabel (connected components labeling) where each blob has a unique ID number assigned at every pixel in the blob.
채택된 답변
Image Analyst
2013년 2월 22일
편집: Image Analyst
2013년 2월 22일
Do you, by chance, mean this:
measurements = regionprops(Iseg, Idata, 'MeanIntensity);
allMeanIntensities= = [measurements.MeanIntensity];
댓글 수: 5
Image Analyst
2013년 2월 25일
Something like (untested)
newImage = intlut(labeledImage, allMeanIntensities);
추가 답변 (1개)
Jan
2013년 2월 22일
At first you can cleanup the loop a little bit using logical indexing:
NumRegion = max(max(Iseg));
mean_magnitude = zeros(size(Iseg));
for i = 1:NumRegion
iIndList = (Iseg == i);
mean_magnitude(iIndList) = mean(Idata(iIndList));
end
I assume accumarray is faster. I'd try to run a loop over Iseq instead also, but I cannot test it due to the absence of test data. It might be helpful if you post some, e.g. produced by some rand calls.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!