-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
108 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# imrankfilter | ||
|
||
```julia | ||
J = imrankfilter(I::GMTimage; width::Int=3, height::Int=0, rank=0.5)::GMTimage | ||
``` | ||
|
||
*keywords: GMT, Julia, image rank filter* | ||
|
||
Rank order filter. | ||
|
||
This defines, for each pixel, a neighborhood of pixels given by a rectangle "centered" on the pixel. | ||
This set of ``width x height`` pixels has a distribution of values, and if they are sorted in increasing | ||
order, we choose the pixel such that rank*(wf*hf-1) pixels have a lower or equal value and (1-rank)*(wf*hf-1) | ||
pixels have an equal or greater value. In other words, `rank=0` returns the minimun, `rank=1` returns | ||
the maximum in box and `rank=0.5` returns the median. Other values return the quantile. | ||
|
||
### Args | ||
- `I::GMTimage`: Input image. This can be a RGB, grayscale or a binary image. | ||
|
||
### Kwargs | ||
- `width::Int=3`: Width of the filter. | ||
|
||
- `height::Int`: Height of the filter (defaults to `width`). | ||
|
||
- `rank=0.5`: Rank. | ||
|
||
### Returns | ||
A new \myreflink{GMTimage} of the same type as `I` with the filtered image. | ||
|
||
Example | ||
------- | ||
|
||
\begin{examplefig}{} | ||
```julia | ||
using GMT | ||
|
||
I = gmtread(TESTSDIR * "assets/small_squares.png"); | ||
J = imrankfilter(I, width=10); | ||
grdimage(I, figsize=6) | ||
grdimage!(J, figsize=6, xshift=6, show=true) | ||
``` | ||
\end{examplefig} | ||
|
||
See Also | ||
-------- | ||
|
||
\myreflink{imdilate}, \myreflink{imerode}, \myreflink{imopen}, \myreflink{imclose} |
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,58 @@ | ||
# imsegment | ||
|
||
```julia | ||
J = function imsegment(I::GMTimage{<:UInt8, 3}; maxdist::Int=0, maxcolors::Int=0, selsize::Int=3, colors::Int=5)::GMTimage | ||
``` | ||
|
||
*keywords: GMT, Julia, image segmentation* | ||
|
||
Unsupervised RGB color segmentation. | ||
|
||
For more details see the docs in Leptonica's function ``pixColorSegment`` (in src/colorseg.c). | ||
|
||
### Args | ||
- `I::GMTimage{<:UInt8, 3}`: Input RGB image. | ||
|
||
### Kwargs | ||
- `maxdist::Int=0`: Maximum euclidean dist to existing cluster. | ||
|
||
- `maxcolors::Int=0`: Maximum number of colors allowed in first pass. | ||
|
||
- `selsize::Int=3`: Size of the structuring element for closing to remove noise. | ||
|
||
- `colors::Int=5`: Number of final colors allowed after 4th pass. | ||
|
||
As a very rough guideline (Leptonica docs), given a target value of `colors`, here are | ||
approximate values of `maxdist` and `maxcolors`: | ||
|
||
| `colors` | `maxcolors` | `maxdist` | | ||
|----------|-------------|-----------| | ||
| 2 | 4 | 150 | | ||
| 3 | 6 | 100 | | ||
| 4 | 8 | 90 | | ||
| 5 | 10 | 75 | | ||
| 6 | 12 | 60 | | ||
| 7 | 14 | 45 | | ||
| 8 | 16 | 30 | | ||
|
||
### Returns | ||
A new, indexed, \myreflink{GMTimage} with the segmentation. | ||
|
||
Examples | ||
-------- | ||
|
||
This was thought as a simple example but turned out to show a bit tricky result. The image | ||
"bunny_cenora.jpg" is simple and we can clearly see that it has only 6 colors, so we would | ||
expect that `colors=6` would do the job. But in fact we need to set `colors=7` because | ||
the outline (black) is in fact picked as two different (dark) colors. | ||
|
||
\begin{examplefig}{} | ||
```julia | ||
using GMT | ||
|
||
I = gmtread(TESTSDIR * "assets/bunny_cenora.jpg"); | ||
J = imsegment(I, colors=7); | ||
grdimage(I, figsize=6) | ||
grdimage!(J, figsize=6, xshift=6, show=true) | ||
``` | ||
\end{examplefig} |