# Overlapping (Transparent?) Images and Measuring Percent White Pixels

2 views (last 30 days)
Sarah on 30 Aug 2018
Edited: jonas on 30 Aug 2018
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');
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 jonas on 30 Aug 2018
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.

R2018a

### Community Treasure Hunt

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

Start Hunting!