How can I find the overlap between two binary volumes?

I'm trying to compare two volumes consisting of 3D white shapes on a black background using matlab 2013 for windows.
1) I want to know how much they overlap over all. Correct me if I'm wrong but I think I can use the nnz function to do that.
2) I want to know where the volumes do not overlap. I have no clue how to accomplish this.
Any help is appreciated.

 Accepted Answer

Define "find the overlap". To get the overlap image:
overlapImage = binaryVolume1 & binaryVolume2;
% To count number of pixels
numOverlapPixels = nnz(overlapImage);

4 Comments

Dalas
Dalas on 19 Jul 2013
Edited: Dalas on 19 Jul 2013
Given two 3d arrays with equal number of x,y,z coordinates (256 by 256 by 256 for example) where each coordinate can either be a one (white) or a zero (black). I want to find out how many coordinates match between the two arrays and make a new binary image stack or volume which shows where the original two volumes have the same values and where they have non-matching values.
% Create the volumes:
binaryVolume1 = false(256,256,256);
binaryVolume2 = false(256,256,256);
% "Light up" pixels
for k = 1 : size(x)
row = y(k);
column = x(k);
slice = z(k);
binaryVolume1(row, column, slice) = true;
end
Then do for the other volume, binaryVolume2, with its x,y, and z. Then use the code above in my answer to find overlap or matching voxels.
I dont need to create the volumes I already have them i just need to analyze them.
I'm looking at mri brain scans by the way just so you have some context of what im working on.
I geuss the volumes arn't actually volumes either their simply stacked 2d "brain slices". We arnt using 3d mr image aquisition. But I think for matlabs purposes its the same as a 3d volume.
Would xor work on 3d arrays?
We're ignoring tissue differences and converting the images into a binary image to focus on brain volume at the moment rather than pathology.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!