Skip to content

Commit 2e66c75

Browse files
authored
fix Transformation and Canny demos (#184)
- add necessary dependencies to Project.toml - generate appropriate gif cover
1 parent f046831 commit 2e66c75

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ ImageBinarization = "cbc4b850-ae4b-5111-9e64-df94c024a13d"
1313
ImageContrastAdjustment = "f332f351-ec65-5f6a-b3d1-319c6670881a"
1414
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
1515
ImageDraw = "4381153b-2b60-58ae-a1ba-fd683676385f"
16+
ImageEdgeDetection = "2b14c160-480b-11ea-1b58-656063328ff7"
1617
ImageFeatures = "92ff4b2b-8094-53d3-b29d-97f740f06cef"
1718
ImageFiltering = "6a3955dd-da59-5b1f-98d4-e7296123deb5"
1819
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
1920
ImageMetadata = "bc367c6b-8a6b-528e-b4bd-a4b897500b49"
2021
ImageMorphology = "787d08f9-d448-5407-9aad-5290dd7ab264"
2122
ImageSegmentation = "80713f31-8817-5129-9cf8-209ff8fb23e1"
2223
ImageShow = "4e3cecfd-b093-5904-9786-8bbb286a6a31"
24+
ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795"
2325
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
2426
IndirectArrays = "9b13fd28-a010-5f03-acff-a1bbcff69959"
2527
MappedArrays = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900"
@@ -47,13 +49,15 @@ ImageBinarization = "0.2"
4749
ImageContrastAdjustment = "0.3"
4850
ImageCore = "0"
4951
ImageDraw = "0"
52+
ImageEdgeDetection = "0"
5053
ImageFeatures = "0"
5154
ImageFiltering = "0"
5255
ImageMagick = "0, 1"
5356
ImageMetadata = "0"
5457
ImageMorphology = "0.2"
5558
ImageSegmentation = "1"
5659
ImageShow = "0"
60+
ImageTransformations = "0"
5761
Images = "0.23"
5862
IndirectArrays = "0"
5963
MappedArrays = "0"

docs/examples/spatial_transformation/SpatialTransformations.jl

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
# ---
22
# title: Cropping, Resizing and Rescaling
3-
# cover: assets/lighthouse.png
3+
# cover: assets/transformations.gif
44
# author: Ashwani Rathee
55
# date: 2020-11-24
66
# ---
77

8-
# This demonstration shows how to use cropping,resizing and rescaling operations on an
8+
# This demonstration shows how to use cropping, resizing and rescaling operations on an
99
# image in Julia using ImageTransformations.jl
1010

11-
using Images, ImageTransformations, TestImages, OffsetArrays
11+
using Images, TestImages, OffsetArrays
12+
## ImageTransformations is reexported by Images
1213
## load an example image
13-
img_source = testimage("lighthouse")
14+
img_source = testimage("lighthouse")
1415

1516
# ## Cropping Operation
1617

17-
# Cropping is one of the most basic photo manipulation processes, and it is carried out to
18-
# remove an unwanted object or irrelevant noise from the periphery of a photograph, to
18+
# Cropping is one of the most basic photo manipulation processes, and it is carried out to
19+
# remove an unwanted object or irrelevant noise from the periphery of a photograph, to
1920
# change its aspect ratio, or to improve the overall composition.
2021

2122
# Let's first check the size of the image
@@ -29,7 +30,7 @@ img_size = size(img_source)
2930
# !!! tip
3031
# An related issue about the memory order is the indexing performance, see [Performance Tips](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-column-major) for more details.
3132

32-
# Let's crop the image from sides by 1/8 of img_source each side and leave it as it is from
33+
# Let's crop the image from sides by `1/8` of `img_source` each side and leave it as it is from
3334
# top to bottom.
3435

3536
# Easiest way to do this is indexing: `img_source[y1:y2, x1:x2]`
@@ -45,7 +46,10 @@ size(img_cropped)
4546

4647
# We can also do size-preserved cropping of the image by replacing the contents of image to white pixels or transparent pixels using PaddedView:
4748

48-
img_padded = PaddedView(ARGB(0, 0, 0, 0), OffsetArray(img_cropped, OffsetArrays.Origin(1, floor(Int, 1/8*img_size[2]))), axes(img_source))
49+
img_padded = PaddedView(
50+
zero(eltype(img_source)),
51+
OffsetArray(img_cropped, OffsetArrays.Origin(1, floor(Int, 1/8*img_size[2]))),
52+
axes(img_source))
4953

5054
# ## Resizing Operation
5155

@@ -59,9 +63,9 @@ mosaicview(img_source, img_square, img_small, img_medium; nrow=1)
5963

6064
# ## Rescaling
6165

62-
# Rescale operation resizes an image by a given scaling factor. The scaling factor can
63-
# either be a single floating point value, or multiple values - one along each axis.
64-
# Image scaling is the process of changing the size of an image while preserving the
66+
# Rescale operation resizes an image by a given scaling factor. The scaling factor can
67+
# either be a single floating point value, or multiple values - one along each axis.
68+
# Image scaling is the process of changing the size of an image while preserving the
6569
# original aspect ratio.
6670

6771
# ### Rescaling by percentage
@@ -82,13 +86,17 @@ new_size = trunc.(Int, size(img_source) .* percentage_scale);
8286
img_rescaled = imresize(img_source, new_size);
8387
mosaicview(img_source, img_rescaled; nrow=1)
8488

85-
# We have updated our scale by percentage solution to calculate scale-percentage
89+
# We have updated our scale by percentage solution to calculate scale-percentage
8690
# dynamically based on a change in one of the dimensions.
87-
# Remember: `size(sourceimage) == (height, width)
91+
# Remember: `size(sourceimage) == (height, width)`
8892

8993
# ### Rescaling by two-fold using restrict function
9094

9195
rescaled_both = restrict(img_source); # both side
92-
rescaled_height = restrict(img_source, 1); # height
93-
rescaled_width = restrict(img_source, 2); # width
96+
rescaled_height = restrict(img_source, 1); # dims=1, i.e., height dimension
97+
rescaled_width = restrict(img_source, 2); # dims=2, i.e., width dimension
9498
mosaicview(img_source, rescaled_both, rescaled_height, rescaled_width; nrow=1)
99+
100+
using ImageMagick #src
101+
out_img = cat(sym_paddedviews(colorant"black", img_source, img_cropped, img_square, rescaled_both)...; dims=3); #src
102+
ImageMagick.save("assets/transformations.gif", out_img; fps=2) #src

0 commit comments

Comments
 (0)