Skip to content

Commit 7199983

Browse files
committed
Add many
1 parent bbcda18 commit 7199983

14 files changed

Lines changed: 1368 additions & 52 deletions

File tree

Interoperability.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ viz(A, colorbar=true)
169169
using GMT, Rasters
170170
import NCDatasets
171171

172-
url = "https://www.unidata.ucar.edu/software/netcdf/examples/tos_O1_2001-2002.nc";
172+
url = "https://archive.unidata.ucar.edu/software/netcdf/examples/tos_O1_2001-2002.nc";
173173
filename = download(url, "tos_O1_2001-2002.nc");
174174
A = Raster(filename);
175175
viz(A[Ti=6], proj=:guess, coast=true, colorbar=true)
@@ -180,6 +180,9 @@ viz(A[Ti=6], proj=:guess, coast=true, colorbar=true)
180180
```julia
181181
using GMT, Rasters # Hide
182182
import NCDatasets # Hide
183+
url = "https://archive.unidata.ucar.edu/software/netcdf/examples/tos_O1_2001-2002.nc"; # Hide
184+
filename = download(url, "tos_O1_2001-2002.nc"); # Hide
185+
A = Raster(filename); # Hide
183186
viz(A[Ti=1:6], proj=:Robinson, coast=true, colorbar=true)
184187
```
185188
\end{examplefig}
@@ -188,7 +191,11 @@ But _I Don't like Kelvins_. Fine, want centigrade? Just offset the _z_ values.
188191

189192
\begin{examplefig}{}
190193
```julia
191-
using GMT
194+
using GMT, Rasters # Hide
195+
import NCDatasets # Hide
196+
url = "https://archive.unidata.ucar.edu/software/netcdf/examples/tos_O1_2001-2002.nc"; # Hide
197+
filename = download(url, "tos_O1_2001-2002.nc"); # Hide
198+
A = Raster(filename); # Hide
192199

193200
G = mat2grid(A[Ti=1:6], offset=-273.15);
194201
viz(G, proj=:Robinson, coast=true, colorbar=true)

documentation/all_docs_ref/all_refs.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
| gmtdefaults | gmtget | gmtinfo | gmtlogo | \myreflink{gmtmath} | gmtregress | \myreflink{gmtselect} | \myreflink{gmtset} |
1717
| \myreflink{gmtsimplify} | gmtspatial | \myreflink{gmtsplit} | gmtvector | gmtwhich | \myreflink{grd2cpt} | \myreflink{grd2kml} | \myreflink{grd2xyz} |
1818
| grdblend | \myreflink{grdclip} | \myreflink{grdcontour} | grdconvert | \myreflink{grdcut} | grdedit | grdfft | \myreflink{grdfill} |
19-
| grdfilter | grdgdal | \myreflink{grdgradient} | \myreflink{grdhisteq} | \myreflink{grdimage} | \myreflink{grdinfo} | grdinterpolate | \myreflink{grdlandmask} |
19+
| \myreflink{grdfilter} | grdgdal | \myreflink{grdgradient} | \myreflink{grdhisteq} | \myreflink{grdimage} | \myreflink{grdinfo} | grdinterpolate | \myreflink{grdlandmask} |
2020
| \myreflink{grdmask} | \myreflink{grdmath} | grdmix | \myreflink{grdpaste} | grdproject | \myreflink{grdsample} | \myreflink{grdtrack} | \myreflink{grdtrend} |
2121
| \myreflink{grdvector} | \myreflink{grdview} | grdvolume | greenspline | \myreflink{histogram} | \myreflink{image} | \myreflink{inset} | kml2gmt |
22-
| \myreflink{legend} | \myreflink{makecpt} | mapproject | \myreflink{mask} | \myreflink{movie} | \myreflink{nearneighbor} | \myreflink{plot} | \myreflink{plot3d} |
22+
| \myreflink{legend} | \myreflink{makecpt} | \myreflink{mapproject} | \myreflink{mask} | \myreflink{movie} | \myreflink{nearneighbor} | \myreflink{plot} | \myreflink{plot3d} |
2323
| \myreflink{project} | psconvert | \myreflink{rose} | \myreflink{sample1d} | \myreflink{solar} | \myreflink{spectrum1d} | sph2grd | sphdistance |
2424
| \myreflink{sphinterpolate} | \myreflink{sphtriangulate} | \myreflink{subplot} | \myreflink{surface} | \myreflink{ternary} | \myreflink{text} | \myreflink{trend1d} | \myreflink{trend2d} |
2525
| \myreflink{triangulate} | \myreflink{wiggle} | \myreflink{xyz2grd} | | | | | |
@@ -84,10 +84,11 @@ its use requires resorting to the \myreflink{Monolithic} mode.
8484

8585
| | | | | | | | |
8686
|:-----|:----|:----|:----|:----|:----|:----|:----|
87-
| \myreflink{binarize} | \myreflink{bwareaopen} | \myreflink{bwhitmiss} | \myreflink{bwperim} | \myreflink{bwskell} | \myreflink{fillsinks} | \myreflink{imbothat} | \myreflink{imclose} |
88-
| \myreflink{imcomplement} | \myreflink{imdilate} | \myreflink{imerode} | \myreflink{imfill} | \myreflink{imfilter} | \myreflink{imhdome} | \myreflink{imhmin} | \myreflink{imhmax} |
89-
| \myreflink{immorphgrad} | \myreflink{imopen} | \myreflink{imrankfilter} | \myreflink{imreconstruct} | \myreflink{imsegment} | \myreflink{imsobel} | \myreflink{imtophat} | \myreflink{isodata} |
90-
| \myreflink{padarray} | \myreflink{strel} | \myreflink{rgb2gray} | \myreflink{rgb2lab} | \myreflink{rgb2ycbcr} | | | |
87+
| \myreflink{binarize} | \myreflink{bwareaopen} | \myreflink{bwconncomp} | \myreflink{bwdist} | \myreflink{bwhitmiss} | \myreflink{bwperim} | \myreflink{bwskell} | \myreflink{cc2bw} |
88+
| \myreflink{fillsinks} | \myreflink{graydist} | \myreflink{imbothat} | \myreflink{imclose} | \myreflink{imcomplement} | \myreflink{imdilate} | \myreflink{imerode} | \myreflink{imfill} |
89+
| \myreflink{imfilter} | \myreflink{imhdome} | \myreflink{imhmin} | \myreflink{imhmax} | \myreflink{immorphgrad} | \myreflink{imopen} | \myreflink{imrankfilter} | \myreflink{imreconstruct} |
90+
| \myreflink{imregionalmax} | \myreflink{imregionalmin} | \myreflink{imsegment} | \myreflink{imsobel} | \myreflink{imtophat} | \myreflink{isodata} | \myreflink{padarray} | \myreflink{strel} |
91+
| \myreflink{rgb2gray} | \myreflink{rgb2lab} | \myreflink{rgb2ycbcr} | | | | | | |
9192

9293
## GDAL utility functions
9394

documentation/modules/contourf.md

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ Create filled contour mapps.
99
Description
1010
-----------
1111

12-
This module is a wrapper to \myreflink{grdview}, *contour* and \myreflink{grdcontour} and as such it works with two different kinds of input data. If input is a grid (either a grid file name or a GMTgrid object) it will make a filled contour with *grdview* and optionally overlay contours by calling \myreflink{grdcontour}. If, on the other hand, the input data is table data file or a Mx3 array (or GMTdataset), it first compute a Delaunay triangulation and makes the plot from it. In this later case, the job is done by *contour* module alone.
12+
This module is a wrapper to \myreflink{grdview}, *contour* and \myreflink{grdcontour} and as such it works with two
13+
different kinds of input data. If input is a grid (either a grid file name or a GMTgrid object) it will make a filled
14+
contour with *grdview* and optionally overlay contours by calling \myreflink{grdcontour}. If, on the other hand,
15+
the input data is table data file or a Mx3 array (or GMTdataset), it first compute a Delaunay triangulation and makes
16+
the plot from it. In this later case, the job is done by *contour* module alone.
17+
18+
Optionaly one can plot the so called Tanaka contours. These are contour lines whose thickness and intensity vary based
19+
on illumination direction, creating an illusion of 3D relief. Illuminated slopes get lighter/thinner lines, shaded slopes
20+
get darker/thicker lines. This is a slow method (not to be used with large grids) but with a nice visual effect.
21+
See the **tanaka** option.
1322

1423
The **region** option can be used to select a map region larger or smaller than that implied by the extent of the grid.
1524

@@ -46,9 +55,9 @@ Optional Arguments
4655

4756
2. If ``cont_int`` is a constant or an array it means plot those contour intervals. This works also to draw
4857
single contours. *E.g.* **contour=[0]** will draw only the zero contour. The **annot** option offers the same
49-
possibility so they may be used together to plot a single annotated contour and another single non-annotated contour,
50-
as in **anot=[10], cont=[5]** that plots an annotated 10 contour and an non-annotated 5 contour. If **annot** is set
51-
and **cont** is not, then the contour interval is set equal to the specified annotation interval.
58+
possibility so they may be used together to plot a single annotated contour and another single non-annotated contour,
59+
as in **anot=[10], cont=[5]** that plots an annotated 10 contour and an non-annotated 5 contour. If **annot** is set
60+
and **cont** is not, then the contour interval is set equal to the specified annotation interval.
5261

5362
If no **contour** option and no *GMTcpt* are passed then for grid a default color map is computed and all of
5463
those automatically contours are drwan. Also, no *GMTcpt* and **contour=[array]** computes a cmap with only the
@@ -79,7 +88,7 @@ Optional Arguments
7988

8089
- **S** or **skip** : -- *skip=true|"t"*\
8190
Skip all input xyz points that fall outside the region [Default uses all the data in the triangulation].
82-
Alternatively, use **skip="t"* to skip triangles whose three vertices are all outside the region.
91+
Alternatively, use **skip="t"** to skip triangles whose three vertices are all outside the region.
8392
*This option should be used only when input data is a grid*.
8493

8594
- **T** or **ticks** : -- *ticks=(local\_high=true, local\_low=true, gap=gap, closed=true, labels=labels)*\
@@ -93,6 +102,11 @@ Optional Arguments
93102
label strings with a comma (*e.g.*, *labels="lo,hi"*). If a file is given by **cont**, and **ticks** is set,
94103
then only contours marked with upper case C or A will have tick marks [and annotations].
95104

105+
- **tanaka** : -- *tanaka=true* **|** *tanaka=azimuth*\
106+
Draw Tanaka-style contours with varying line thickness and intensity to simulate illumination from a
107+
given direction. The *azimuth* (in degrees) gives the illumination direction (default is 315 degrees,
108+
i.e., NW). Tanaka contours are a bit slow to compute so avoid using this option with large grids.
109+
96110
\textinput{common_opts/opt_U}
97111

98112
\textinput{common_opts/opt_V}
@@ -121,9 +135,9 @@ Using a grid
121135

122136
\begin{examplefig}{}
123137
```julia
124-
using GMT
138+
using GMT # Hide
125139

126-
G = GMT.peaks();
140+
G = peaks();
127141
C = makecpt(T=(-7,9,2));
128142

129143
contourf(G, show=1)
@@ -145,4 +159,14 @@ using GMT
145159
d = [0 2 5; 1 4 5; 2 0.5 5; 3 3 9; 4 4.5 5; 4.2 1.2 5; 6 3 1; 8 1 5; 9 4.5 5];
146160
contourf(d, limits=(-0.5,9.5,0,5), pen=0.25, labels=(line=(:min,:max),), show=1)
147161
```
162+
\end{examplefig}
163+
164+
Tanaka contours
165+
166+
\begin{examplefig}{}
167+
```julia
168+
using GMT # Hide
169+
G = peaks();
170+
contourf(G, tanaka=true, show=true)
171+
```
148172
\end{examplefig}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# bwconncomp
2+
3+
```julia
4+
CC = bwconncomp(BW; conn=8)
5+
```
6+
7+
Find and count connected components in binary image.
8+
9+
## Description
10+
11+
Finds and counts the connected components in the binary image `BW`. The function returns a structure
12+
containing the total number of connected components, such as regions of interest (ROIs), in the image
13+
and the pixel indices assigned to each component.
14+
15+
## Parameters
16+
17+
- **BW**: Binary 2D image. For numeric input, any nonzero pixels are considered to be 1 (true).
18+
- **Type**: `Array{<:Real}` or `GMTgrid`
19+
20+
## Keyword Arguments
21+
22+
- **conn**: Connectivity for connected components
23+
- **Type**: `Integer` or `Array`
24+
- **Default**: `8`
25+
- **Options**:
26+
- For 2D images:
27+
- `4` — 4-connected neighborhood (edge connectivity)
28+
- `8` — 8-connected neighborhood (edge and corner connectivity)
29+
- Alternatively, can be a connectivity array of 0s and 1s with the same dimensionality as `BW`. The 1-valued elements define neighborhood locations relative to the center element. The center element must be 1. The connectivity array size must be odd along each dimension.
30+
31+
## Returns
32+
33+
Connected components, specified as a structure with the following fields:
34+
35+
| Field | Description |
36+
|-------|-------------|
37+
| `connectivity` | Connectivity of the connected components |
38+
| `image_size` | Size of the binary image |
39+
| `num_objects` | Number of connected components in the binary image |
40+
| `range` | Range of the image coordinates |
41+
| `inc` | Image's increment (!= 1 whem image is referenced) |
42+
| `registration` | Registration of the image |
43+
| `x` | X coordinates of the image |
44+
| `y` | Y coordinates of the image |
45+
| `layout` | Memory layout of the image |
46+
| `proj4` | Projection definition (optional) |
47+
| `wkt` | Well-known text definition (optional) |
48+
| `epsg` | EPSG code of the image |
49+
| `bbox` | The bounding boxes as a vector of GMTdataset |
50+
| `pixel_list` | Vector where each element contains the linear indices of the pixels in each object |
51+
| `centroid` | A Float64 Matrix with the x,y coordinates of the centroids for each component |
52+
| `area` | A vector of Float64 with the areas of each component |
53+
54+
- To compute a label matrix with a memory-efficient data type (for instance, `UInt8` versus `Float64`),
55+
use the `labelmatrix` function on the output of `bwconncomp`:
56+
57+
```julia
58+
CC = bwconncomp(BW)
59+
L = labelmatrix(CC)
60+
```
61+
62+
## Examples
63+
64+
### Find Connected Components in Binary Image
65+
66+
```julia
67+
using GMT
68+
69+
# Create a binary image
70+
BW = [1 1 0 0 0 0 0 0
71+
1 1 0 1 1 0 0 0
72+
0 0 0 1 1 0 0 0
73+
0 0 0 0 0 1 1 0
74+
0 0 0 0 0 1 1 0
75+
0 0 0 0 0 0 0 0]
76+
77+
# Find connected components
78+
CC = bwconncomp(BW)
79+
80+
println("Number of connected components: ", CC.num_objects)
81+
```
82+
83+
### Specify Connectivity
84+
85+
Find connected components using 4-connectivity instead of the default 8-connectivity:
86+
87+
```julia
88+
using GMT
89+
90+
BW = [1 1 0 0 0 0 0 0
91+
1 1 0 1 1 0 0 0
92+
0 0 0 1 1 0 0 0
93+
0 0 0 0 0 1 1 0
94+
0 0 0 0 0 1 1 0
95+
0 0 0 0 0 0 0 0]
96+
97+
# 4-connectivity
98+
CC4 = bwconncomp(BW, conn=4)
99+
println("Number of components (4-conn): ", CC4.num_objects)
100+
101+
# 8-connectivity
102+
CC8 = bwconncomp(BW, conn=8)
103+
println("Number of components (8-conn): ", CC8.num_objects)
104+
```
105+
106+
### Extract Properties of Connected Components
107+
108+
Use the output structure to analyze individual components:
109+
110+
```julia
111+
using GMT
112+
113+
BW = [1 1 0 0 0 0 0 0
114+
1 1 0 1 1 0 0 0
115+
0 0 0 1 1 0 0 0
116+
0 0 0 0 0 1 1 0
117+
0 0 0 0 0 1 1 0
118+
0 0 0 0 0 0 0 0]
119+
120+
CC = bwconncomp(BW)
121+
122+
# Number of pixels in each component
123+
numPixels = [length(CC.pixel_list[i]) for i in 1:CC.num_objects]
124+
println("Pixels per component: ", numPixels)
125+
126+
# Find the largest component
127+
largest = argmax(numPixels)
128+
println("Largest component is #", largest, " with ", numPixels[largest], " pixels")
129+
```
130+
131+
## See Also
132+
133+
\myreflink{cc2bw}

0 commit comments

Comments
 (0)