Removing a portion from a single volume

I have a 3D skeletonized Image(skel2) and it is a single volume. it is a fibrous structure and I want to remove the portion in the red coloured area. Just only that blob.But it is a single volume because that blob is the same material of other material and it is a part of the volume.regionprops3() also says that it is a single volume.This skel2 is a 3d array(522x366x490 logical array).I know bwareaopen() can be used to remove separeated volumes.But It does not work this as I want to remove the blob which is already connected to the single volume.Appreciate your advices/comments.

Answers (1)

Tim
Tim on 9 Dec 2020
Edited: Tim on 9 Dec 2020
The fiberous portions would probably disappear, leaving the blob as a residual if you use an erosion operator, becauses they are much narrower (it looks from the figure, anyway). Try using something like:
% example volume
data = zeros(522, 366, 490);
% Add some fibers that are interconnected
data(100, 100, :) = 1;
data(:, 100, 50) = 1;
data(100, :, 30) = 1;
% Now add a blob
data(100-10:100+10, 100-10:100+10, 30-10:30+10) = 1;
% Get rid of fibers using errosion
w = 3; % set erosion width here
edata = imerode(data, ones(w, w, w)); % Erode to get rid of fibers
volshow(data); % Original
figure;
volshow(edata); % Blob is left over
You can play with erosion width w to figure out the appropriate size to get rid of the fibers but leave enough of the blob behind to determine its location

6 Comments

Hi Tim, Thank you very much for the answer. Actually, I want to remove the blob. not the fibres. And also, if I erode the volume, it will change the (x,y,z) coodinates of the fibers. My intention is to remove that blob which is connected to the fibres and all of them are now as a single volume as it is connected.Appreciate your comments.
Sure - the point is if you erode the fibers you can detect the blob then do whatever you want (e.g. get rid of it in the original volume). For example, to remove the blob, do the following:
%% Blob removal example:
% example volume
data = zeros(522, 366, 490);
% Add some fibers that are interconnected
data(100, 100, :) = 1;
data(:, 100, 50) = 1;
data(100, :, 30) = 1;
% Now add a blob
data(100-10:100+10, 100-10:100+10, 30-10:30+10) = 1;
% Get rid of fibers using errosion
w = 3; % set erosion width here
edata = imerode(data, ones(w, w, w)); % Erode to get rid of fibers
% make blob mask:
blob_mask = 1 - imdilate(edata, ones(w, w, w));
% apply blob mask to original set:
data_no_blob = data.*blob_mask;
figure;
volshow(data_no_blob)
Hege
Hege on 9 Dec 2020
Edited: Hege on 9 Dec 2020
@Tim, Thank you very mcuh for your reply. I tried it. But the problem is, when the fibres are eroded, blob is also eroded and disappered with the fibres as it is the same material which means blob is also made by fibres. So, blob is a high concentrated set of fibres of same material. Actually, I mentioned it in the question that the blob and fibres are same materials. Appreciate your comments!
I still think a dilation/erosion combination is a good bet if you play around with it. If the blob is disappearing it is because it isn't a contiguous "blob." You could fix that with a dilation operation. Consider the following example that I'm going to make 2D for simplicity, where a "blob" disappears because it has a lot of small cavities, however the density is much higher. In this case dilatio->erosion->dilation works.
Alternatively, you could convolve with a 3D smoothing kernel and look for a dense region using a threshold... that's another alternative. Detect the dense region and make a mask. Example code below:
%%
dat2 = zeros(100, 100);
dat2(5:20, 5:20) = 1;
dat2(randn(size(dat2)) > 1.5) = 1; % sprinkle ones in here.
% this could be like the fibers
dat2(randn(size(dat2)) > 0.0) = 0; % add cavities...
subplot(2, 3, 1)
imagesc(dat2)
title('Original');
subplot(2, 3, 2)
imagesc(imerode(dat2, ones(3)))
title('Eroded');
subplot(2, 3, 3)
imagesc(imdilate(imerode(imdilate(dat2,...
ones(3)), ones(6)), ones(6)));
title('Dilated-Eroded-Dilated');
% filtering...
subplot(2, 3, 4)
imagesc(dat2);
title('Original');
subplot(2, 3, 5)
cW = 20;
imagesc(conv2(dat2, ones(cW)/cW^2, 'same'))
title('filtered');
subplot(2, 3, 6);
thresh = 0.2; % density threshold
imagesc(imdilate(conv2(dat2, ones(cW)/cW^2, 'same')>thresh, ones(5)))
title('Blob mask')
This example produces the following (would swap out conv2 for convn in your case):
@Tim, Thank you very much for the reply. I really appreciate it. I thought and checked it. But I wonder how we can threshold a binary image and how the locations(x,y,z) dimensions of fibres are changed.(Locations of the x,y,z dimensions are important to me.It is fine if there is a slight change but not a considerable change).
However, your other idea was really nice. but I wonder how I detect the high density volume in the binray image. if I can detect the high density volume and convalute by a mask, that would be great.
Another idea which was in my mind is to detect the joint points of the fibres and break it from the joint points. then we can remove the short fibres(bwareaopen()) as the blob contains short fibers. But I am thinking how to idenfy the joint points(joints points-where the fibres meet each others).
Appreciate your comments and really thankful for your valuable time!
The processes above are meant to generate binary masks to encapsulate the region of interest (the blob) in the original image. Neither of them should change xyz feature locations if they are being applied as intended. Regarding convolution: I suggest making some 3D kernel, convolving, then empirically determining the threshold value you need by making a binary mask using the > operation and a threshold and visualizing the result using volshow.There's a bunch of ways to tackle your problem, you may not find these approaches effective but there are plenty of other ways and you may have to be creative

Sign in to comment.

Asked:

on 8 Dec 2020

Commented:

Tim
on 10 Dec 2020

Community Treasure Hunt

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

Start Hunting!