필터 지우기
필터 지우기

Overlapping (Transparent?) Images and Measuring Percent White Pixels

조회 수: 2 (최근 30일)
Sarah
Sarah 2018년 8월 30일
편집: jonas 2018년 8월 30일
I have generated images of white circles on a black background (see the attached image as an example). I want to overlap these images where they are translated randomly in the x and y direction. Then I want to measure the percent white pixels that are overlapped. Attached is my current code, which doesn't work very well at giving an accurate measurement of the overlapping white pixels. Please help.
m = NoOfIterations; % Choose number of iterations (ex. 25)
n = NoOfOverlappingImages; % Choose number of overlapping images (ex. 8)
h = SpaceBtwnCircles; % Choose the distance between circles (ex. 1)
k = DiameterOfCircles; % Choose the diameter of the circles (ex. 1)
Phase = h+k;
f1 = figure;
for a = 1:m
for z = 1:n
r1 = rand(1)*Phase;
r2 = rand(1)*Phase;
rectangle('Position',[r1 r2 9*(k+h)+k 9*(k+h)+k], 'FaceColor', [0 0 0 0.5]);
for i = 0:9
for j = 0:9
rectangle('Position', [j*(k+h)+r1 i*(k+h)+r2 k k],'Curvature',[1 1], 'FaceColor',[1 1 1 0.5]);
end
end
end
set(gca,'visible','off');
figname = strcat(num2str(h), num2str(k),'_',num2str(n),'.png');
print(figname, '-dpng', '-r0');
IM = imbinarize(imread(figname));
BW = IM(:,:,2);
[y1,x1]=find(BW==0,1,'first');
[y2,x2]=find(BW==0,1,'last');
CropBW=BW(y1:y2,x1:x2);
SAExposed = (nnz(CropBW)/numel(CropBW))*100;
matSA(a,:) = SAExposed;
close(f1);
end
  댓글 수: 6
Sarah
Sarah 2018년 8월 30일
The values varied, so it was to be specified for each test. I updated the code to provide reasonable numbers for these selections.
jonas
jonas 2018년 8월 30일
편집: jonas 2018년 8월 30일
I don't have a complete answer so I'll post my half-hearted attempt here.
If you remove the rectangle, then you are left with a bunch of overlapping blobs. If you know the radius of a single circle, then you can easily calculate the total area assuming zero overlap (always 100 circles right per rectangle right?). You can then take the total area of pixels having the same color as the circles and subtract from the total area, leaving you with the overlapping area.
I'm just struggling to determine the area of a single circle. imfindcircles was not helpful.
Another problem is that the circles seems to have slightly different area when rendered, which may or may not have a negligible effect on the results.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by