Segmenting an image into homogenous compartments

Hello all.
I have an MRI scan that I need to segment into N homogenous compartments for later reconstruction. The challenge here is that it's not whatever organ, and the rest is background, but it has to be compartments.
What tool can be used for that?

 Accepted Answer

I believe you're describing superpixels3
help superpixels3
SUPERPIXELS3 3-D superpixel over-segmentation of 3-D images [L,NumLabels] = superpixels3(A,N) computes 3-D superpixels of 3-D image A using N as the requested number of superpixels. N must be between 1 and the number of pixels in the image A. The first output argument, L, is a label matrix of type double. The second output argument, NumLabels, is the actual number of 3-D superpixels that were computed. [L,NumLabels] = superpixels3(___,Name,Value,...) computes superpixels of A with Name-Value pairs used to control aspects of the segmentation. Parameters include: 'Compactness' - Numeric scalar specifying the compactness parameter of the SLIC algorithm. Compactness controls the shape of superpixels. A higher value for compactness makes superpixels more regularly shaped/square. A lower value makes superpixels adhere to boundaries better, making them irregularly shaped. The allowed range of Compactness is (0 Inf). Typical values for Compactness are in the range [0.01, 0.1]. If this parameter is not specified, the default value is chosen as 0.001 if METHOD is 'slic0' and 0.05 if METHOD is 'slic'. 'Method' - String specifying the algorithm used to compute superpixels. Supported options are 'slic' and 'slic0'. When 'Method' is 'slic0', the SLIC0 algorithm is used to adaptively refine 'Compactness' after the first iteration. When 'Method' is 'slic', 'compactness' is constant during clustering. Default: 'slic0' 'NumIterations' - Numeric scalar specifying the number of iterations used in the clustering phase of the algorithm. For most problems it is not necessary to adjust this parameter. Default: 10 Class Support ------------- The input image A must be a real, non-sparse matrix of the following classes: int8, uint8, int16, uint16, int32, uint32, single, or double. Notes ----- 1. When using the 'slic0' method, it is generally not necessary to adjust 'Compactness' parameter. The intention of 'slic0' is to adaptively refine 'Compactness' automatically and eliminate the need for users to determine a good value of 'Compactness' for themselves. References: ----------- [1] Radhakrishna Achanta, Appu Shaji, Kevin Smith, Aurelien Lucchi, Pascal Fua, and Sabine Susstrunk, SLIC Superpixels Compared to State-of-the-art Superpixel Methods, IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 34, num. 11, p. 2274 - 2282, May 2012. [2] Radhakrishna Achanta, Appu Shaji, Kevin Smith, Aurelien Lucchi, Pascal Fua, and Sabine Susstrunk, SLIC Superpixels, EPFL Technical Report no. 149300, June 2010. Example ------- % Compute 3-D superpixels of input volumetric intensity image. Form an % output image where each pixel is set to the mean color of its % corresponding superpixel region. load mri; D = squeeze(D); A = ind2gray(D,map); [L,N] = superpixels3(A, 34); % Show all xy-planes progressively with superpixel boundaries. imSize = size(A); % Create a stack of RGB images to display the boundaries in color. imPlusBoundaries = zeros(imSize(1),imSize(2),3,imSize(3),'uint8'); for plane = 1:imSize(3) BW = boundarymask(L(:, :, plane)); % Create an RGB representation of this plane with boundary shown % in cyan. imPlusBoundaries(:, :, :, plane) = imoverlay(A(:, :, plane), BW, 'cyan'); end implay(imPlusBoundaries,5) % Set color of each pixel in output image to the mean intensity of % the superpixel region. % Show the mean image next to the original. pixelIdxList = label2idx(L); meanA = zeros(size(A),'like',D); for superpixel = 1:N memberPixelIdx = pixelIdxList{superpixel}; meanA(memberPixelIdx) = mean(A(memberPixelIdx)); end implay([A meanA],5); See also superpixels, boundarymask, imoverlay, label2idx, implay. Documentation for superpixels3 doc superpixels3

7 Comments

Zinoviy
Zinoviy on 26 Feb 2023
Edited: Zinoviy on 26 Feb 2023
My image is 2D, but there exists a 2D version of the function that I will try and report results.
Thanks!
@Zinoviy yes there is. For other people, here's what you may expect from superpixels (from the demo)
It basically segments the image into zones/regions of similar characteristics.
If you want to wait for others to answer with different suggestions, you can. Once you have an Answer that solves your original question, then could you please click the "Accept this answer" link to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.
Well it sort of does what I want but not exactly. I use N=100 because I think it's kind of appropriate, but it results in oversegmentation. Is there a way to add some of the superpixels? I see there is one such option in the segment editor, but I want to use the mask I generated instead of what it does automatically.
Thanks!
You can use whatever mask you want. If you hand draw one, or get one by some other method (like thresholding), it doesn't matter. Just use whichever one works best for you. I'm attaching some hand drawing method demos.
Ok, I don't think that what I'm looking for.
In the Image Segmenter there is a superpixel option, but Is there a way to adjust the value ore so I can add regions? See for example my N=100 vs the segmenter. I just want to add togeather relevant areas, and reduce the overall number of compartments.
Thanks!
I haven't used that tool so I don't know if there is a way to manually change the regions it found.
I understand. Do have an idea what I can do instead?
Thanks!

Sign in to comment.

More Answers (0)

Products

Release

R2022b

Asked:

on 26 Feb 2023

Commented:

on 28 Feb 2023

Community Treasure Hunt

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

Start Hunting!