Skip to content

Commit 6bc0db9

Browse files
committed
Two new IP funs
1 parent f7e5bf0 commit 6bc0db9

File tree

4 files changed

+108
-2
lines changed

4 files changed

+108
-2
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
1010
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
1111
Franklin = "713c75ef-9fc9-4b05-94a9-213340da978e"
1212
GMT = "5752ebe1-31b9-557e-87aa-f909b540aa54"
13-
Gumbo = "708ec375-b3d6-5a57-a7ce-8257bf98657a"
13+
#Gumbo = "708ec375-b3d6-5a57-a7ce-8257bf98657a"
1414
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
1515
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
1616
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"

documentation/all_docs_ref/all_refs.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ its use requires resorting to the \myreflink{Monolithic} mode.
6565
|:-----|:----|:----|:----|:----|:----|:----|:----|
6666
| \myreflink{binarize} | \myreflink{bwhitmiss} | \myreflink{bwperim} | \myreflink{bwskell} | \myreflink{fillsinks} | \myreflink{imbothat} | \myreflink{imclose} | \myreflink{imcomplement} |
6767
| \myreflink{imdilate} | \myreflink{imerode} | \myreflink{imfill} | \myreflink{imhdome} | \myreflink{imhmin} | \myreflink{imhmax} | \myreflink{immorphgrad} | \myreflink{imopen} |
68-
| \myreflink{imreconstruct} | \myreflink{imtophat} | \myreflink{isodata} | \myreflink{padarray} | \myreflink{strel} | \myreflink{rgb2gray} | \myreflink{rgb2lab} | \myreflink{rgb2ycbcr} |
68+
| \myreflink{imreconstruct} | \myreflink{imrankfilter} | \myreflink{imsegment} | \myreflink{imtophat} | \myreflink{isodata} | \myreflink{padarray} | \myreflink{strel} | \myreflink{rgb2gray} |
69+
| \myreflink{rgb2lab} | \myreflink{rgb2ycbcr} | | | | | | |
6970

7071

7172
## GDAL utility functions
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# imrankfilter
2+
3+
```julia
4+
J = imrankfilter(I::GMTimage; width::Int=3, height::Int=0, rank=0.5)::GMTimage
5+
```
6+
7+
*keywords: GMT, Julia, image rank filter*
8+
9+
Rank order filter.
10+
11+
This defines, for each pixel, a neighborhood of pixels given by a rectangle "centered" on the pixel.
12+
This set of ``width x height`` pixels has a distribution of values, and if they are sorted in increasing
13+
order, we choose the pixel such that rank*(wf*hf-1) pixels have a lower or equal value and (1-rank)*(wf*hf-1)
14+
pixels have an equal or greater value. In other words, `rank=0` returns the minimun, `rank=1` returns
15+
the maximum in box and `rank=0.5` returns the median. Other values return the quantile.
16+
17+
### Args
18+
- `I::GMTimage`: Input image. This can be a RGB, grayscale or a binary image.
19+
20+
### Kwargs
21+
- `width::Int=3`: Width of the filter.
22+
23+
- `height::Int`: Height of the filter (defaults to `width`).
24+
25+
- `rank=0.5`: Rank.
26+
27+
### Returns
28+
A new \myreflink{GMTimage} of the same type as `I` with the filtered image.
29+
30+
Example
31+
-------
32+
33+
\begin{examplefig}{}
34+
```julia
35+
using GMT
36+
37+
I = gmtread(TESTSDIR * "assets/small_squares.png");
38+
J = imrankfilter(I, width=10);
39+
grdimage(I, figsize=6)
40+
grdimage!(J, figsize=6, xshift=6, show=true)
41+
```
42+
\end{examplefig}
43+
44+
See Also
45+
--------
46+
47+
\myreflink{imdilate}, \myreflink{imerode}, \myreflink{imopen}, \myreflink{imclose}

documentation/utilities/imsegment.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# imsegment
2+
3+
```julia
4+
J = function imsegment(I::GMTimage{<:UInt8, 3}; maxdist::Int=0, maxcolors::Int=0, selsize::Int=3, colors::Int=5)::GMTimage
5+
```
6+
7+
*keywords: GMT, Julia, image segmentation*
8+
9+
Unsupervised RGB color segmentation.
10+
11+
For more details see the docs in Leptonica's function ``pixColorSegment`` (in src/colorseg.c).
12+
13+
### Args
14+
- `I::GMTimage{<:UInt8, 3}`: Input RGB image.
15+
16+
### Kwargs
17+
- `maxdist::Int=0`: Maximum euclidean dist to existing cluster.
18+
19+
- `maxcolors::Int=0`: Maximum number of colors allowed in first pass.
20+
21+
- `selsize::Int=3`: Size of the structuring element for closing to remove noise.
22+
23+
- `colors::Int=5`: Number of final colors allowed after 4th pass.
24+
25+
As a very rough guideline (Leptonica docs), given a target value of `colors`, here are
26+
approximate values of `maxdist` and `maxcolors`:
27+
28+
| `colors` | `maxcolors` | `maxdist` |
29+
|----------|-------------|-----------|
30+
| 2 | 4 | 150 |
31+
| 3 | 6 | 100 |
32+
| 4 | 8 | 90 |
33+
| 5 | 10 | 75 |
34+
| 6 | 12 | 60 |
35+
| 7 | 14 | 45 |
36+
| 8 | 16 | 30 |
37+
38+
### Returns
39+
A new, indexed, \myreflink{GMTimage} with the segmentation.
40+
41+
Examples
42+
--------
43+
44+
This was thought as a simple example but turned out to show a bit tricky result. The image
45+
"bunny_cenora.jpg" is simple and we can clearly see that it has only 6 colors, so we would
46+
expect that `colors=6` would do the job. But in fact we need to set `colors=7` because
47+
the outline (black) is in fact picked as two different (dark) colors.
48+
49+
\begin{examplefig}{}
50+
```julia
51+
using GMT
52+
53+
I = gmtread(TESTSDIR * "assets/bunny_cenora.jpg");
54+
J = imsegment(I, colors=7);
55+
grdimage(I, figsize=6)
56+
grdimage!(J, figsize=6, xshift=6, show=true)
57+
```
58+
\end{examplefig}

0 commit comments

Comments
 (0)