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

    12    17    12     2     2    14     1    11    21    19     7    22    12

  Columns 14 through 15

    17    12


A_uni =

     1     2     7    11    12    14    17    19    21    22


ind1 =

     7     4    11     8     1     6     2    10     9    12


ind2 =

  Columns 1 through 13

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

  Columns 14 through 15

     7     5


Ac =

  Columns 1 through 13

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

  Columns 14 through 15

     2     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 =

    23    12    24     8    23    22
     2    11    22     8    20    20
    13     3    25     3    10    13
    22     7     0     1     3    23
    14     4     4    18    22    23


A_uni =

     0
     1
     2
     3
     4
     7
     8
    10
    11
    12
    13
    14
    18
    20
    22
    23
    24
    25


ind1 =

    14
    19
     2
     8
    10
     9
    16
    23
     7
     6
     3
     5
    20
    22
     4
     1
    11
    13


ind2 =

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


Ac =

     4     1     1     2     4     4
     1     1     4     2     2     2
     2     3     1     3     1     2
     4     1     1     1     3     4
     1     2     2     1     4     4

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 3: 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) =

    22     3    19    15
    20     3     1     7
     3    12    17    22


A(:,:,2) =

    12     1    17     5
     3     2     9     8
     3    12     9    22


A_uni =

     1
     2
     3
     5
     7
     8
     9
    12
    15
    17
    19
    20
    22


ind1 =

     8
    17
     3
    22
    11
    23
    20
     6
    10
     9
     7
     2
     1


ind2(:,:,1) =

    13     3    11     9
    12     3     1     5
     3     8    10    13


ind2(:,:,2) =

     8     1    10     4
     3     2     7     6
     3     8     7    13


Ac(:,:,1) =

     3     5     1     1
     1     5     2     1
     5     3     2     3


Ac(:,:,2) =

     3     2     2     1
     5     1     2     1
     5     3     2     3

Example 4: Using 'rows' option

n=5;
m=3;

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

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

    13    25    21
    21     4    20
    12     0    20
    14    11    18
    13    25    21


A_uni =

    12     0    20
    13    25    21
    14    11    18
    21     4    20


ind1 =

     3
     1
     4
     2


ind2 =

     2
     4
     1
     3
     2


Ac =

     2
     1
     1
     1
     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/.