How can I smooth out the voids/holes created with topology optimization algorithm?

2 views (last 30 days)
I'm using this 'top99neo' topology optimization code to generate the following structures: top99neo
As talked about in the paper, I'm using 'pasV' to enforce voids throughout the design- in my case, circles. But, as you can see in the images below, the holes are very sharp/awkward- the voids formed around the holes aren't continuous w/ the radius of the holes. Is there some smoothing filter I can apply that makes the resulting voids more continuous in shape? For instance, I'd like the voids to be as smooth as the one in the last image below.

Answers (1)

Image Analyst
Image Analyst on 16 Oct 2022
Not really sure what is a hole and a void. Are the holes the Octagons wit a gray level of 255? If so just threshold for those to get a hole mask then fill appropriate parts. Full demo:
% Demo by Image Analyst
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 = 22;
markerSize = 40;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
folder = [];
baseFileName = '#90_nelx_100_nely_150_vf_0.31_maxit_150_penal_6_rmin_4_comp_254_time_24.png';
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% 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
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 2, 1);
imshow(grayImage);
impixelinfo;
axis('on', 'image');
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
fprintf('It is not really gray scale like we expected - it is color\n');
% Extract the blue channel.
grayImage = grayImage(:, :, 3);
end
% Update the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
% Maximize window.
g = gcf;
g.WindowState = 'maximized';
drawnow;
%--------------------------------------------------------------------------------------------------------
% Threshold the image to get the bright blobs.
% https://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image?s_tid=srchtitle
lowThreshold = 255;
highThreshold = 255;
% [lowThreshold, highThreshold, lastThresholdedBand] = threshold(lowThreshold, highThreshold, grayImage)
holeMask = grayImage >= lowThreshold & grayImage <= highThreshold;
% Get rid of part touching the edge of the image.
holeMask = imclearborder(holeMask);
% Fill holes.
holeMask = imfill(holeMask, 'holes');
subplot(2, 2, 2);
imshow(holeMask)
title('Binary Mask Image', 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% Get the black part
blackMask = ~bwareafilt(grayImage == 255, 1);
% Erode it a bit
se = strel('disk', 20, 0);
blackMask = imerode(blackMask, se);
% Fill holes.
blackMask = imfill(blackMask, 'holes');
subplot(2, 2, 3);
imshow(blackMask)
title('Black Part Mask', 'FontSize', fontSize, 'Interpreter', 'None');
% Make that part in the original image black.
grayImage2 = grayImage; % Initialize.
grayImage2(blackMask) = 0;
% Now write the white part into the image
grayImage2(holeMask) = 255;
subplot(2, 2, 4);
imshow(grayImage2)
title('Part With Holes Only', 'FontSize', fontSize, 'Interpreter', 'None');

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!