Skip to content

Commit bb38d34

Browse files
authored
Merge pull request #708 from Mathics3/doc-revisions
Doc updates and add mising morph.py
2 parents 2d9b1a9 + d38229d commit bb38d34

File tree

6 files changed

+176
-12
lines changed

6 files changed

+176
-12
lines changed

mathics/builtin/image/morph.py

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
"""
2+
Morphological Image Processing
3+
"""
4+
5+
from mathics.builtin.base import Builtin
6+
from mathics.builtin.image.base import Image, _SkimageBuiltin
7+
from mathics.core.convert.python import from_python
8+
from mathics.core.evaluation import Evaluation
9+
from mathics.eval.image import matrix_to_numpy, pixels_as_float, pixels_as_ubyte
10+
11+
12+
class _MorphologyFilter(_SkimageBuiltin, Builtin):
13+
"""
14+
Base class for many Morphological Image Processing filters.
15+
This requires scikit-mage to be installed.
16+
"""
17+
18+
messages = {
19+
"grayscale": "Your image has been converted to grayscale as color images are not supported yet."
20+
}
21+
22+
rules = {"%(name)s[i_Image, r_?RealNumberQ]": "%(name)s[i, BoxMatrix[r]]"}
23+
24+
def eval(self, image, k, evaluation: Evaluation):
25+
"%(name)s[image_Image, k_?MatrixQ]"
26+
if image.color_space != "Grayscale":
27+
image = image.grayscale()
28+
evaluation.message(self.get_name(), "grayscale")
29+
import skimage.morphology
30+
31+
f = getattr(skimage.morphology, self.get_name(True).lower())
32+
shape = image.pixels.shape[:2]
33+
img = f(image.pixels.reshape(shape), matrix_to_numpy(k))
34+
return Image(img, "Grayscale")
35+
36+
37+
class Closing(_MorphologyFilter):
38+
"""
39+
<url>
40+
:WMA link
41+
:https://reference.wolfram.com/language/ref/Closing.html</url>
42+
43+
<dl>
44+
<dt>'Closing[$image$, $ker$]'
45+
<dd>Gives the morphological closing of $image$ with respect to structuring element $ker$.
46+
</dl>
47+
48+
>> ein = Import["ExampleData/Einstein.jpg"];
49+
>> Closing[ein, 2.5]
50+
= -Image-
51+
"""
52+
53+
summary_text = "morphological closing regarding a kernel"
54+
55+
56+
class Dilation(_MorphologyFilter):
57+
"""
58+
<url>
59+
:WMA link:
60+
https://reference.wolfram.com/language/ref/Dilation.html</url>
61+
62+
<dl>
63+
<dt>'Dilation[$image$, $ker$]'
64+
<dd>Gives the morphological dilation of $image$ with respect to structuring element $ker$.
65+
</dl>
66+
67+
>> ein = Import["ExampleData/Einstein.jpg"];
68+
>> Dilation[ein, 2.5]
69+
= -Image-
70+
"""
71+
72+
summary_text = "give the dilation with respect to a range-r square"
73+
74+
75+
class Erosion(_MorphologyFilter):
76+
"""
77+
<url>
78+
:WMA link:
79+
https://reference.wolfram.com/language/ref/Erosion.html</url>
80+
81+
<dl>
82+
<dt>'Erosion[$image$, $ker$]'
83+
<dd>Gives the morphological erosion of $image$ with respect to structuring element $ker$.
84+
</dl>
85+
86+
>> ein = Import["ExampleData/Einstein.jpg"];
87+
>> Erosion[ein, 2.5]
88+
= -Image-
89+
"""
90+
91+
summary_text = "give the erotion with respect to a range-r square"
92+
93+
94+
class MorphologicalComponents(_SkimageBuiltin):
95+
"""
96+
<url>
97+
:WMA link:
98+
https://reference.wolfram.com/language/ref/MorphologicalComponents.html</url>
99+
100+
<dl>
101+
<dt>'MorphologicalComponents[$image$]'
102+
<dd> Builds a 2-D array in which each pixel of $image$ is replaced \
103+
by an integer index representing the connected foreground image \
104+
component in which the pixel lies.
105+
106+
<dt>'MorphologicalComponents[$image$, $threshold$]'
107+
<dd> consider any pixel with a value above $threshold$ as the foreground.
108+
</dl>
109+
"""
110+
111+
summary_text = "tag connected regions of similar colors"
112+
113+
rules = {"MorphologicalComponents[i_Image]": "MorphologicalComponents[i, 0]"}
114+
115+
def eval(self, image, t, evaluation: Evaluation):
116+
"MorphologicalComponents[image_Image, t_?RealNumberQ]"
117+
pixels = pixels_as_ubyte(
118+
pixels_as_float(image.grayscale().pixels) > t.round_to_float()
119+
)
120+
import skimage.measure
121+
122+
return from_python(
123+
skimage.measure.label(pixels, background=0, connectivity=2).tolist()
124+
)
125+
126+
127+
class Opening(_MorphologyFilter):
128+
"""
129+
<url>
130+
:WMA link:
131+
https://reference.wolfram.com/language/ref/Opening.html</url>
132+
133+
<dl>
134+
<dt>'Opening[$image$, $ker$]'
135+
<dd>Gives the morphological opening of $image$ with respect to structuring element $ker$.
136+
</dl>
137+
138+
>> ein = Import["ExampleData/Einstein.jpg"];
139+
>> Opening[ein, 2.5]
140+
= -Image-
141+
"""
142+
143+
summary_text = "get morphological opening regarding a kernel"
144+
145+
146+
# TODO DistanceTransform, Thinning, Pruning,
147+
# and lots of others under "Morophological Transforms

mathics/doc/common_doc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@
9999
r"<em>Mathematica</em>&reg;",
100100
r"\emph{Mathematica}\textregistered{}",
101101
),
102-
"Mathics": (r"<em>Mathics</em>", r"\emph{Mathics}"),
102+
"Mathics": (r"<em>Mathics3</em>", r"\emph{Mathics3}"),
103+
"Mathics3": (r"<em>Mathics3</em>", r"\emph{Mathics3}"),
103104
"Sage": (r"<em>Sage</em>", r"\emph{Sage}"),
104105
"Wolfram": (r"<em>Wolfram</em>", r"\emph{Wolfram}"),
105106
"skip": (r"<br /><br />", r"\bigskip"),
@@ -624,7 +625,7 @@ def strip_sentinal(line):
624625
any blanks that appear before will be preserved.
625626
626627
Some tests require some lines to be blank or entry because
627-
Mathics output can be that way
628+
Mathics3 output can be that way
628629
"""
629630
if line.endswith(END_LINE_SENTINAL):
630631
line = line[: -len(END_LINE_SENTINAL)]

mathics/doc/documentation/1-Manual.mdoc

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,20 @@ Some of the features of \Mathics are:
5252
</section>
5353

5454
<section title="History">
55-
The version alpha version of \Mathics was done in 2011 by Jan Pöschko. He worked on it for a couple of years to about v0.5 which had 386 built-in symbols.
55+
The first alpha versions of \Mathics were done in 2011 by Jan Pöschko. He worked on it for a couple of years to about v0.5 which had 386 built-in symbols. Currently there are over a 1,000.
5656

57-
After that Angus Griffith took over primary leadership and rewrote the parser to pretty much the stage it is in now. He and later Ben Jones worked on it from 2013 to about 2017 to the v1.0 release. Towards the end of this period Bernhard Liebl worked on this mostly focused on graphics.
57+
After that, Angus Griffith took over primary leadership and rewrote the parser to pretty much the stage it is in now. He and later Ben Jones worked on it from 2013 to about 2017 to the v1.0 release. Towards the end of this period, Bernhard Liebl worked on this mostly focused on graphics.
5858

5959
A <url>:docker image of the v.9 release: https://hub.docker.com/r/arkadi/mathics</url> can be found on dockerhub.
6060

6161
The project was largely abandoned in its Python 2.7 state around 2017. Subsequently it was picked up by the current developers. A list of authors and contributors can be found in the
62-
<url>:<con>AUTHORS.txt</con>: https://github.com/Mathics-3/mathics/blob/master/AUTHORS.txt</url> file.
62+
<url>:<con>AUTHORS.txt</con>: https://github.com/Mathics3/mathics-core/blob/master/AUTHORS.txt</url> file.
6363
</section>
6464

6565
<section title="What is missing?">
6666
There are lots of ways in which \Mathics could still be improved. <url>:<con>FUTURE.rst</con>: https://github.com/Mathics-3/mathics/blob/master/FUTURE.txt</url> has the current roadmap.
6767

68-
While we always could use Python programming help, there are numerous other ways where we could use assistance.
68+
While we always could use help, such as in Python programming, improving Documentation. But there are other ways to help. For example:
6969

7070
<ul>
7171
<li>Ensure this document is complete and accurate. We could use help to ensure all of the Builtin functions described properly and fully, and that they have link to corresponding Wiki, Sympy, WMA and/or mpath links.
@@ -78,6 +78,8 @@ Make sure the builtin summaries and examples clear and useful.</li>
7878
</ul>
7979
</section>
8080

81+
See <url>:The Mathics3 Developer Guide:https://mathics-development-guide.readthedocs.io/en/latest/</url> for how to get started using and developing \Mathics.
82+
8183
</chapter>
8284

8385

@@ -1249,7 +1251,7 @@ It is not very sophisticated from a mathematical point of view, but it\'s beauti
12491251

12501252
In the future, we plan on providing an interface to Jupyter as a separate package.
12511253

1252-
However currently as part \Mathics, we distribute a browser-based interface using long-term-release (LTS) Django 3.2.
1254+
However currently as part \Mathics, we distribute a browser-based interface using long-term-release (LTS) Django 4.
12531255

12541256
Since a Jupyter-based interface seems preferable to the home-grown interface described here, it is doubtful whether there will be future improvements to the this interface.
12551257

@@ -1259,6 +1261,9 @@ It looks like this:
12591261

12601262
<imgpng src="menubar.png" title="Mathics Menu Bar" label="menubar">
12611263

1264+
These save and load worksheets, share sessions, run a gallery of examples, go to the GitHub organization page, and provide information about the particular Mathics3 installation.
1265+
1266+
These are explained in the sections below.
12621267

12631268
<section title="URIs">
12641269

@@ -1275,6 +1280,7 @@ Assuming your are running locally or on a host called 'localhost' using the defa
12751280
<li>directory path information for the current setup
12761281
<li>machine information
12771282
<li>system information
1283+
<li>customizable system settings
12781284
</ul>
12791285
<dt><url>http://localhost:8000/doc</url>
12801286
<dd>An on-line formatted version of the documentation, which include this text. You can see this as a right side frame of the main page, when clicking "?" on the right-hand upper corner.
@@ -1298,7 +1304,17 @@ Saved worksheets can be loaded or deleted using the <em>File Open</em> button wh
12981304

12991305
Depending on browser, desktop, and OS-settings, the "Ctrl+O" key combination may do the same thing.
13001306

1301-
A popup menu should appear with the list of saved worksheets with an option to either load or delete the worksheet.
1307+
A pop-up menu should appear with the list of saved worksheets with an option to either load or delete the worksheet.
1308+
1309+
</section>
1310+
1311+
<section title="Gallery Examples">
1312+
1313+
We have a number of examples showing off briefly some of the capabilities of the system. These are run when you hit hit the button that looks like this:
1314+
1315+
<imgpng src="gallery.png" title="Run Gallery Demo examples Button" label="gallery-button">
1316+
1317+
It is also shown in the pop-up text that appears when Mathics3 is first run.
13021318

13031319
</section>
13041320

@@ -1332,7 +1348,7 @@ There are some keyboard commands you can use in the Django-based Web interface o
13321348
<dt>'Shift+Return'</dt>
13331349
<dd>This evaluates the current cell (the most important one, for sure). On the right-hand side you may also see an "=" button which can be clicked to do the same thing.</dd>
13341350
<dt>'Ctrl+D'</dt>
1335-
<dd>This moves the cursor over to the documentation pane on the right-hand side. From here you can preform a search for a pre-defined \Mathics function, or symbol. Clicking on the "?" symbol on the right-hand side does the same thing.</dd>
1351+
<dd>This moves the cursor over to the documentation pane on the right-hand side. From here you can perform a search for a pre-defined \Mathics function, or symbol. Clicking on the "?" symbol on the right-hand side does the same thing.</dd>
13361352
<dt>'Ctrl+C'</dt>
13371353
<dd>This moves the cursor back to document code pane area where you type \Mathics expressions</dd>
13381354
<dt>'Ctrl+S'</dt>
572 Bytes
Loading
693 Bytes
Loading

mathics/doc/latex/mathics.tex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
% -*- latex -*-
22
%
3-
% This is the top-level LaTeX file to build the Mathics Book (Tutorial + Reference)
3+
% This is the top-level LaTeX file to build the Mathics3 Book (Tutorial + Reference)
44
% which is stored in mathic.pdf
55
%
66
% To build this:
@@ -71,7 +71,7 @@
7171
{\LARGE\color{subtitle}\textit{\textmd{A free, open-source alternative to Mathematica}}}
7272
\par\textmd{\Large Mathics Core Version \MathicsCoreVersion}
7373
}
74-
\author{The Mathics Team}
74+
\author{The Mathics3 Team}
7575

7676

7777
% Fix unicode mappings for listings
@@ -285,7 +285,7 @@
285285
\printindex
286286
\begin{colophon}
287287
\begin{description}
288-
\item[Mathics Core] \hfill \\ \MathicsCoreVersion
288+
\item[Mathics3 Core] \hfill \\ \MathicsCoreVersion
289289
\item[Python] \hfill \\ \PythonVersion
290290
\item[mpmath] \hfill \\ \mpmathVersion
291291
\item[NumpyPy] \hfill \\ \NumPyVersion

0 commit comments

Comments
 (0)