Skip to content

Commit 4d1a52e

Browse files
add JuliaSets
1 parent 50761f6 commit 4d1a52e

File tree

1 file changed

+238
-0
lines changed

1 file changed

+238
-0
lines changed

short_tutorials/JuliaSets.ipynb

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "8607eb0e",
6+
"metadata": {},
7+
"source": [
8+
"# Julia Sets"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": null,
14+
"id": "87bd1a0f",
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"%matplotlib inline\n",
19+
"from matplotlib import pyplot as plt\n",
20+
"import numpy as np"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": null,
26+
"id": "3f5a75af",
27+
"metadata": {},
28+
"outputs": [],
29+
"source": [
30+
"def julia(c, size=256, center=(0.0, 0.0), zoom=1.0, iters=256):\n",
31+
" x, y = np.meshgrid(\n",
32+
" np.linspace(-1, 1, size)/zoom + center[0], \n",
33+
" np.linspace(-1, 1, size)/zoom + center[1], \n",
34+
" )\n",
35+
" z = x + 1j * y\n",
36+
" im = np.zeros(z.shape)\n",
37+
" ix = np.ones(z.shape, dtype=bool)\n",
38+
" for i in range(iters):\n",
39+
" z[ix] = z[ix] ** 2 + c\n",
40+
" ix = np.abs(z) < 2\n",
41+
" im += ix\n",
42+
" return im"
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"execution_count": null,
48+
"id": "79556895",
49+
"metadata": {},
50+
"outputs": [],
51+
"source": [
52+
"plt.imshow(julia(-0.4+0.6j), cmap='magma')\n",
53+
"plt.axis(False);"
54+
]
55+
},
56+
{
57+
"cell_type": "code",
58+
"execution_count": null,
59+
"id": "a43baa42",
60+
"metadata": {},
61+
"outputs": [],
62+
"source": [
63+
"plt.imshow(julia(-0.4+0.6j, center=(0.34, -0.30), zoom=10000.0), cmap='magma')\n",
64+
"plt.axis(False);"
65+
]
66+
},
67+
{
68+
"cell_type": "code",
69+
"execution_count": null,
70+
"id": "3c63ce73",
71+
"metadata": {},
72+
"outputs": [],
73+
"source": [
74+
"c = (\n",
75+
" -0.4 + 0.6j, \n",
76+
" -0.74543 + 0.11301j, \n",
77+
" -0.75 + 0.11j, \n",
78+
" -0.1 + 0.651j,\n",
79+
" -0.835 - 0.2321j,\n",
80+
" -0.70176 - 0.3842j,\n",
81+
")"
82+
]
83+
},
84+
{
85+
"cell_type": "code",
86+
"execution_count": null,
87+
"id": "cfc85940",
88+
"metadata": {},
89+
"outputs": [],
90+
"source": [
91+
"noise_level = 5.0\n",
92+
"\n",
93+
"fig, ax = plt.subplots(3, 2, figsize=(10, 16))\n",
94+
"for c_, a in zip(c, ax.flatten()):\n",
95+
" img = julia(c_, zoom=0.5) \n",
96+
" img += np.random.randn(*img.shape) * noise_level\n",
97+
" a.imshow(img, cmap='magma')\n",
98+
" a.axis(False)"
99+
]
100+
},
101+
{
102+
"cell_type": "markdown",
103+
"id": "b01e70d9",
104+
"metadata": {},
105+
"source": [
106+
"# Image processing"
107+
]
108+
},
109+
{
110+
"cell_type": "code",
111+
"execution_count": null,
112+
"id": "b4069a34",
113+
"metadata": {},
114+
"outputs": [],
115+
"source": [
116+
"from skimage import data\n",
117+
"from skimage import filters"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": null,
123+
"id": "39bc25c7",
124+
"metadata": {},
125+
"outputs": [],
126+
"source": [
127+
"from skimage.morphology import disk\n",
128+
"from skimage import restoration"
129+
]
130+
},
131+
{
132+
"cell_type": "code",
133+
"execution_count": null,
134+
"id": "aa225a15",
135+
"metadata": {},
136+
"outputs": [],
137+
"source": [
138+
"noise_level = 50.0\n",
139+
"img = julia(-0.4+0.6j, size=200)\n",
140+
"noise_img = img + np.random.randn(*img.shape) * noise_level\n",
141+
"median_img = filters.median(noise_img, disk(3))\n",
142+
"tv_img = restoration.denoise_tv_chambolle(noise_img, weight=20.0)\n",
143+
"wavelet_img = restoration.denoise_wavelet(noise_img)\n",
144+
"gaussian_img = filters.gaussian(noise_img, sigma=1.8)"
145+
]
146+
},
147+
{
148+
"cell_type": "code",
149+
"execution_count": null,
150+
"id": "d60ecafd",
151+
"metadata": {
152+
"scrolled": false
153+
},
154+
"outputs": [],
155+
"source": [
156+
"fig, ax = plt.subplots(3, 2, figsize=(12, 18))\n",
157+
"for a, (im, title) in zip(\n",
158+
" ax.flatten(),\n",
159+
" ((img, 'original'), \n",
160+
" (noise_img, 'original+noise'),\n",
161+
" (gaussian_img, 'gaussian'),\n",
162+
" (median_img, 'median'), \n",
163+
" (wavelet_img, 'wavelet'),\n",
164+
" (tv_img, 'tv'), )):\n",
165+
" a.imshow(im, cmap='magma', vmin=0, vmax=255)\n",
166+
" a.axis(False)\n",
167+
" a.set_title(title)"
168+
]
169+
},
170+
{
171+
"cell_type": "markdown",
172+
"id": "b495345a",
173+
"metadata": {},
174+
"source": [
175+
"# DataJoint Pipeline"
176+
]
177+
},
178+
{
179+
"cell_type": "code",
180+
"execution_count": null,
181+
"id": "9015c43e",
182+
"metadata": {},
183+
"outputs": [],
184+
"source": [
185+
"import datajoint as dj"
186+
]
187+
},
188+
{
189+
"cell_type": "code",
190+
"execution_count": null,
191+
"id": "62067735",
192+
"metadata": {},
193+
"outputs": [],
194+
"source": [
195+
"schema = dj.Schema('julia')"
196+
]
197+
},
198+
{
199+
"cell_type": "code",
200+
"execution_count": null,
201+
"id": "4c4ef4a9",
202+
"metadata": {},
203+
"outputs": [],
204+
"source": [
205+
"img.max()"
206+
]
207+
},
208+
{
209+
"cell_type": "code",
210+
"execution_count": null,
211+
"id": "5630641b",
212+
"metadata": {},
213+
"outputs": [],
214+
"source": []
215+
}
216+
],
217+
"metadata": {
218+
"kernelspec": {
219+
"display_name": "benv",
220+
"language": "python",
221+
"name": "benv"
222+
},
223+
"language_info": {
224+
"codemirror_mode": {
225+
"name": "ipython",
226+
"version": 3
227+
},
228+
"file_extension": ".py",
229+
"mimetype": "text/x-python",
230+
"name": "python",
231+
"nbconvert_exporter": "python",
232+
"pygments_lexer": "ipython3",
233+
"version": "3.10.4"
234+
}
235+
},
236+
"nbformat": 4,
237+
"nbformat_minor": 5
238+
}

0 commit comments

Comments
 (0)