-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added overloads to dip::MinimumVariancePartitioning() and dip::KMeans…
…Clustering().
- Loading branch information
1 parent
5fa2964
commit a8950e0
Showing
13 changed files
with
177 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import diplib as dip | ||
import numpy as np | ||
|
||
|
||
input = dip.ImageRead('examples/DIP.tif') | ||
dip.viewer.Show(input) | ||
|
||
# Compute histogram and cluster it | ||
hist = dip.Histogram(input, configuration=dip.Histogram.Configuration(0.0, 255.0, 64)) | ||
centers = dip.MinimumVariancePartitioning(hist, out=hist, nClusters=3) | ||
|
||
# Reverse lookup to create the segmented image | ||
labels = hist.ReverseLookup(input) | ||
dip.viewer.Show(labels, mapping="8bit", lut="labels") | ||
|
||
# A color lookup table to paint each label with the cluster center RGB values | ||
centers.insert(0, [0.0, 0.0, 0.0]) # label #0 doesn't have an entry in centers, this aligns the labels to the indices | ||
lut = dip.LookupTable(dip.Image(np.array(centers), tensor_axis=1)) | ||
output = lut.Apply(labels) | ||
|
||
output.SetColorSpace(input.ColorSpace()) | ||
dip.viewer.Show(output) | ||
dip.viewer.Spin() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.