cunique

Below is a demonstration of the features of the cunique function

Contents

clear; close all; clc;

Syntax

[A_uni,ind1,ind2,Ac]=cunique(A);

Description

The imx function provides a figure window based GUI for 3D image segmentation

Examples

Plot settings

fontSize=20;

Example 1: Getting unique entries and occurance counts for 1xN arrays

n=15;
A=round(25*rand(1,n)); %Rounded random set in range 0-25
A(1)=A(end); %Force at least one double occurance for this example
A

%Get unique set and counts
[A_uni,ind1,ind2,Ac]=cunique(A)
A =

  Columns 1 through 13

     2     8    11     3    25     8     7     2     7     1    13    19    16

  Columns 14 through 15

     2     2


A_uni =

     1     2     3     7     8    11    13    16    19    25


ind1 =

    10     1     4     7     2     3    11    13    12     5


ind2 =

  Columns 1 through 13

     2     5     6     3    10     5     4     2     4     1     7     9     8

  Columns 14 through 15

     2     2


Ac =

  Columns 1 through 13

     4     2     1     1     1     2     2     4     2     1     1     1     1

  Columns 14 through 15

     4     4

Example 2: Getting unique entries and occurance counts for NxM arrays

n=5;
m=6;
A=round(25*rand(n,m)); %Rounded random set in range 0-25
A(1)=A(end); %Force at least one double occurance for this example
A

%Get unique set and counts
[A_uni,ind1,ind2,Ac]=cunique(A)
A =

    22     8    17    20     2     3
    23     7    15     7    20     3
    13    19    13    17     8    14
     3     0    18    14    15    12
    21     1    18    10    19    22


A_uni =

     0
     1
     2
     3
     7
     8
    10
    12
    13
    14
    15
    17
    18
    19
    20
    21
    22
    23


ind1 =

     9
    10
    21
     4
     7
     6
    20
    29
     3
    19
    12
    11
    14
     8
    16
     5
     1
     2


ind2 =

    17     6    12    15     3     4
    18     5    11     5    15     4
     9    14     9    12     6    10
     4     1    13    10    11     8
    16     2    13     7    14    17


Ac =

     2     2     2     2     1     3
     1     2     2     2     2     3
     2     2     2     2     2     2
     3     1     2     2     2     1
     1     1     2     1     2     2

Visualizing input array and occurange counts

cFigure;
subplot(1,2,1);
title('The input array')
hold on;
imagesc(A);
image_numeric(A,[],0,fontSize);
axis tight; axis equal;
colormap(gca,gjet(max(A(:))));
icolorbar;

subplot(1,2,2);
title('The occurance counts')
hold on;
imagesc(Ac);
image_numeric(Ac,[],0,fontSize);
axis tight; axis equal;
colormap(gca,gjet(max(Ac(:))));
icolorbar;
drawnow;

Example 2: Getting unique entries and occurance counts for NxMx... arrays

n=3;
m=4;
l=2;

A=round(25*rand(n,m,l)); %Rounded random set in range 0-25
A(1)=A(end); %Force at least one double occurance for this example
A

%Get unique set and counts
[A_uni,ind1,ind2,Ac]=cunique(A)
A(:,:,1) =

     9     2    24    18
    18     2    17     3
     1    20     3     3


A(:,:,2) =

    16    19     6    22
     8    15    18     2
    16    19    24     9


A_uni =

     1
     2
     3
     6
     8
     9
    15
    16
    17
    18
    19
    20
    22
    24


ind1 =

     3
     4
     9
    19
    14
     1
    17
    13
     8
     2
    16
     6
    22
     7


ind2(:,:,1) =

     6     2    14    10
    10     2     9     3
     1    12     3     3


ind2(:,:,2) =

     8    11     4    13
     5     7    10     2
     8    11    14     6


Ac(:,:,1) =

     2     3     2     3
     3     3     1     3
     1     1     3     3


Ac(:,:,2) =

     2     2     1     1
     1     1     3     3
     2     2     2     2

GIBBON www.gibboncode.org

Kevin Mattheus Moerman, [email protected]

GIBBON footer text

License: https://github.com/gibbonCode/GIBBON/blob/master/LICENSE

GIBBON: The Geometry and Image-based Bioengineering add-On. A toolbox for image segmentation, image-based modeling, meshing, and finite element analysis.

Copyright (C) 2019 Kevin Mattheus Moerman

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.