Periodic Boundary condition feature in image analysis tools

조회 수: 5 (최근 30일)
N/A
N/A 2015년 9월 2일
이동: Image Analyst 2025년 4월 6일
I'm doing some image analysis. Consider the image below with periodic boundary conditions.
Essentially, I want to count how many clusters there are automatically. Now, I understand that MATLAB has a comprehensive list of circle detection features like imfindcircles. But I am unable to find a circle detection algorithm/setting that recognises periodic boundary conditions in the image. As with my case, I would be left with double counting. I have tried creating my own methods of removing the double counting problem. But my methods are somewhat convoluted so I'm mildly sceptical. My question is if anyone knows of a quickfix/setting/feature that could implement periodic boundary conditions in something like imfindcircles?
Thank you
  댓글 수: 3
palaciosg226
palaciosg226 2020년 6월 8일
Hello, I have the same question. In many applications such as percolation detection, this tool is necessary.
Rachel
Rachel 2025년 3월 31일
I have the same question. I am using an algorithm to identify clusters within a 3D cube. The result that I have right now double-counts the clusters at the edges/corners of the box. Is there a way to account for PBC in MATLAB to avoid double-counting?

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

답변 (3개)

Image Analyst
Image Analyst 2025년 4월 1일
It can be done but it's a bit tricky. You can call imclearborder and then use find() to find out which blobs have pixels in common (actually somewhat different. It would take probably 15 minutes or so to do but first I'd like to know under what circumstances in the real world would give rise to this. Why are the partial blobs on opposite sides of the image actually the same physical object? Give me the real world use case. I don't want to spend time solving what ends up being an XY Problem.

Rachel
Rachel 2025년 4월 4일
The provided coordinates for the clusters are already in wrapped form.

Image Analyst
Image Analyst 2025년 4월 6일
이동: Image Analyst 2025년 4월 6일
Here is a way to "complete" the boundary (edge) blobs. However the blobs are now duplicated on the sides. We could use imclearborder to remove blobs on two of the sides, but if a blob is in a corner, it's replicated 4 times and you'd have to decide which one to keep.
% Demo by Image Analyst
% Initialization steps:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 12;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
folder = pwd;
baseFileName = "spots wrapped.png";
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~isfile(fullFileName)
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
% Read in image file.
grayImage1 = imread(fullFileName);
% Get size
[rows, columns, numberOfColorChannels] = size(grayImage1)
rows = 603
columns = 601
numberOfColorChannels = 3
% Get gray scale version of it.
if numberOfColorChannels == 3
grayImage1 = grayImage1(:, :, 1); % Take red channel.
end
mask = grayImage1 > 128;
% Display the image.
subplot(2, 2, 1);
imshow(mask);
axis('on', 'image');
impixelinfo;
caption = sprintf('Original image : %s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
% Maximize window.
g = gcf;
g.WindowState = 'maximized';
g.Name = 'Demo by Image Analyst';
g.NumberTitle = 'off';
drawnow;
%--------------------------------------------------------------------------------------------------------
% Replicate the image on all sides
mask2 = repmat(mask, 3, 3);
blank = false(rows, columns);
markerImage = [blank, blank, blank; blank, mask, blank; blank, blank, blank];
%--------------------------------------------------------------------------------------------------------
% REPLICATE THE MASK ON ALL SIDES.
% GET BORDER BLOBS ONLY
% borderBlobs = imkeepborder(mask);
% Display the image.
subplot(2, 2, 2);
imshow(mask2);
axis('on', 'image');
impixelinfo;
title('Replicated Mask', 'FontSize', fontSize, 'Interpreter', 'None');
% Display the marker image.
subplot(2, 2, 3);
imshow(markerImage);
axis('on', 'image');
impixelinfo;
title('Marker Blobs', 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% RECONSTRUCT THE INSIDE BLOBS
mask3 = imreconstruct(markerImage, mask2, 4);
% Display the image.
subplot(2, 2, 4);
imshow(mask3);
axis('on', 'image');
impixelinfo;
title('Reconstructed image', 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% CROP THE IMAGE TO THE LARGEST BOUNDING BOX.
[r, c] = find(mask3);
row1 = min(r, [], 'all');
row2 = max(r, [], 'all');
col1 = min(c, [], 'all');
col2 = max(c, [], 'all');
mask4 = mask3(row1 : row2, col1 : col2);
% Display the image.
subplot(2, 2, 4);
imshow(mask4);
axis('on', 'image');
impixelinfo;
title('Reconstructed image', 'FontSize', fontSize, 'Interpreter', 'None');

Community Treasure Hunt

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

Start Hunting!

Translated by