Initialize Packages

A cell with all the import

md"""
# Initialize Packages

A cell with all the import
"""
8.3 ms
begin
using PlutoUI, LinearAlgebra, Images, ImageShow, ImageMagick
end
7.2 s
PlutoUI.TableOfContents()
4.1 ms

Read and Display Image

md"""
# Read and Display Image
"""
253 μs
url
"https://user-images.githubusercontent.com/6933510/107239146-dcc3fd00-6a28-11eb-8c7b-41aaf6618935.png"
url = "https://user-images.githubusercontent.com/6933510/107239146-dcc3fd00-6a28-11eb-8c7b-41aaf6618935.png"
# url ="https://www.google.com/url?sa=i&url=https%3A%2F%2Funsplash.com%2Fs%2Fphotos%2Fegyptian-cat&psig=AOvVaw1xYgdNItObx3eNC5OH7KFT&ust=1649752004968000&source=images&cd=vfe&ved=0CAoQjRxqFwoTCKjvyaTLi_cCFQAAAAAdAAAAABAD"
17.8 μs
philip_fname
"/tmp/jl_AWVsqKX5gD"
philip_fname = download(url)
296 ms
Enter cell code...
82.7 μs
philip
philip = load(philip_fname)
775 ms
Enter cell code...
82.0 μs

Simple Julia Function and Broadcasting

md"""
# Simple Julia Function and Broadcasting
"""
229 μs
double (generic function with 1 method)
function double(x)
return x*2
end
438 μs
4.0
double(2.0)
17.8 μs
a
3×3 Matrix{Int64}:
 1  2   4
 2  3   4
 8  9  24
a = [1 2 4
2 3 4
8 9 24]
28.5 μs
3×3 Matrix{Int64}:
  2   4   8
  4   6   8
 16  18  48
double.(a)
84.1 ms
3×3 Matrix{Int64}:
 1  2   4
 2  3   4
 8  9  24
a
14.7 μs
flatten (generic function with 1 method)
flatten(a)=a[1:1:length(a)] # Flattens a matrix column wise
467 μs
flatten(a)
21.5 μs
Enter cell code...
80.9 μs

Taking Camera Input

This will not work on the remote server

md"""
# Taking Camera Input

This will not work on the remote server
"""
303 μs
@bind image_data FilePicker([MIME("image/jpg"), MIME("image/png")])
272 ms

MethodError: no method matching getindex(::Nothing, ::String)

  1. top-level scope@Local: 1[inlined]
image_data["data"]|> IOBuffer
---
# @bind fname file_input()
17.4 μs
myface1
myface1=philip
18.3 μs

[
myface1 myface1[ : , end:-1:1]
myface1[end:-1:1, :] myface1[end:-1:1, end:-1:1]
]
295 ms
[philip philip[:, end:-1:1]]
65.5 ms
philip[1:2:end, 1:2:end]
509 μs

Inspecting your data

md"""
# Inspecting your data
"""
228 μs
size(philip)
17.9 μs
row_i, col_i = (1,1)
22.3 μs
philip[row_i, col_i]
20.8 μs
Slider(1:10)
20.0 μs
1
Slider(1:10, show_value=true)
7.3 ms

PlutoUI 1 PlutoUI2 1

PlutoUI3 1 PlutoUI4 1

begin
row_start, row_end = (1,100)
col_start, col_end = (1,100)
md"""
PlutoUI $(@bind row_start Slider(1:size(philip)[1], show_value=true))
PlutoUI2 $(@bind row_end Slider(1:size(philip)[1], show_value=true))
PlutoUI3 $(@bind col_start Slider(1:size(philip)[2], show_value=true))
PlutoUI4 $(@bind col_end Slider(1:size(philip)[2], show_value=true))
"""
end
57.5 ms
reduced_phil
reduced_phil = philip[row_start:row_end, col_start:col_end]
33.9 μs
save( "reduced_phil2.png", reduced_phil)
95.0 ms
1
row_start
15.8 μs
864
size(philip)[1]
20.3 μs

Julia: Array Data Structure

md"""
# Julia: Array Data Structure
"""
234 μs
[1, 20, "hello"]
30.2 μs
[RGB(1,0,0), RGB(0,1,0), RGB(0,0,1)]
25.1 μs
[RGB(1,0,0) RGB(0,1,0)
RGB(0,0,1) RGB(0.5, 0.5, 0.5)]
725 ms
[RGB(x,0,0) for x in 0:0.1:1]
81.0 ms
[RGB(i, j, 0) for i in 0:0.1:1, j in 0:0.1:1]
101 ms
[RGB(i, j, 0) for i in 0:0.1:1, j in 0:0.1:1]
86.5 ms
philip_head
philip_head = reduced_phil
17.5 μs
[philip_head reverse(philip_head, dims=2)
reverse(philip_head, dims=1) rot180(philip_head)]
135 ms
1
@bind number_reds Slider(1:100, show_value=true)
947 μs
[RGB(red_value / number_reds, 0, 0) for red_value in 0:number_reds]
53.5 ms

Abstraction

md"""
# Abstraction
"""
225 μs
begin
one_keys = ["1", "1.0", "one", "1//1", "Cute One", "2x2 Identity", "One Corgi"]
end
28.0 μs
selections
selections = one_keys .=> one_keys
82.0 ms
Enter cell code...
95.2 μs
Enter cell code...
96.0 μs
begin
oneimage = load(download("https://gallery.yopriceville.com/var/albums/Free-Clipart-Pictures/Decorative-Numbers/Cute_Number_One_PNG_Clipart_Image.png?m=1437447301"))
corgi = load(download("https://i.barkpost.com/wp-content/uploads/2015/01/corgi2.jpg?q=70&fit=crop&crop=entropy&w=808&h=500"))
nothing
end

1.8 s
one
one = [
1,
1.0,
"one",
1//1,
oneimage,
[1 0; 0 1],
corgi,
]
41.4 μs
lookup_element
lookup_element = Dict(one_keys .=> one)
665 ms
computer_ones
computer_ones = typeof.(one)
48.0 ms
md"$(@bind element_key Select(selections))"
87.0 ms
element
1
element = lookup_element[element_key]
23.4 μs
Int64
typeof(element)
18.5 μs
3×4 Matrix{Int64}:
 1  1  1  1
 1  1  1  1
 1  1  1  1
fill(element, 3, 4)
20.2 μs

Utils

This contains all the utilities used in the pluto notebook. For pluto reactive working style , it is recommended to collect utilities at the end

md"""
# Utils

This contains all the utilities used in the pluto notebook. For pluto reactive working style , it is recommended to collect utilities at the end
"""
299 μs
camera_input (generic function with 1 method)
function camera_input(;max_size=150, default_url="https://i.imgur.com/SUmi94P.png")
"""
<span class="pl-image waiting-for-permission">
<style>
.pl-image.popped-out {
position: fixed;
top: 0;
right: 0;
z-index: 5;
}

.pl-image #video-container {
width: 250px;
}

.pl-image video {
border-radius: 1rem 1rem 0 0;
}
.pl-image.waiting-for-permission #video-container {
display: none;
}
.pl-image #prompt {
display: none;
}
.pl-image.waiting-for-permission #prompt {
width: 250px;
height: 200px;
display: grid;
place-items: center;
font-family: monospace;
font-weight: bold;
text-decoration: underline;
cursor: pointer;
border: 5px dashed rgba(0,0,0,.5);
}
1.5 ms
file_input (generic function with 1 method)
function file_input()
"""
<form>
<label for="fname">File Name</label>
<input type="file" id="fname" name="fname"><br><br>
</form>
"""|>HTML
end
420 μs
HTML()
17.7 μs