Skip to content

Commit f885ef9

Browse files
Added demos: Histogram Equalization and RGB to Grayscale conversion (#133)
* add rgb to gray * add equalization demo Co-authored-by: Johnny Chen <[email protected]>
1 parent bd6126c commit f885ef9

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# ---
2+
# title: RGB to GrayScale
3+
# cover: assets/rgb_grayscale.png
4+
# ---
5+
6+
# This example illustrates RGB to Grayscale Conversion
7+
8+
9+
using ImageCore, TestImages
10+
11+
rgb_image = testimage("lighthouse")
12+
13+
# `I = Gray.(rgb_image)` converts an RGB image to Grayscale.
14+
15+
gray_image = Gray.(rgb_image)
16+
mosaicview(rgb_image, gray_image; nrow = 1)
17+
18+
# Gray scale conversion form RGB follows a weighted sum of all channels, the coffecients are computed according to
19+
# [Rec. ITU-R BT.601-7](https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.601-7-201103-I!!PDF-E.pdf) rounding off to 3 decimal places
20+
# `0.299 * R + 0.587 * G + 0.114 * B`
21+
22+
save("assets/rgb_grayscale.png", gray_image) #src
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# ---
2+
# title: Histogram equalisation
3+
# cover: assets/histogram_equalization.png
4+
# ---
5+
6+
# This demo issustrates the use of [Histogram equalization](https://juliaimages.org/ImageContrastAdjustment.jl/stable/reference/#Equalization-1), [gamma correction matching](https://juliaimages.org/ImageContrastAdjustment.jl/stable/reference/#Matching-1)
7+
# and [Contrast Limited Adaptive Histogram Equalization](https://juliaimages.org/ImageContrastAdjustment.jl/stable/reference/#AdaptiveEqualization-1)
8+
9+
# Histogram equalisation is used to imporve the contrast in an
10+
# single-channel grayscale image. It distributes the intensity of the image
11+
# in a uniform manner. The natural justification for uniformity
12+
# is that the image has better contrast if the intensity levels of an image span
13+
# a wide range on the intensity scale. The transformation is based on mapping of
14+
# cumulative histogram
15+
16+
using ImageContrastAdjustment, TestImages, ImageCore
17+
18+
img = testimage("moonsurface")
19+
20+
# Now we will apply Histogram equalisation, gamma correction and Adaptive histogram equalisation
21+
# method to enhance contrast of the image
22+
23+
hist_equal = adjust_histogram(img, Equalization(nbins = 256))
24+
gamma_correction = adjust_histogram(img, GammaCorrection(gamma = 2))
25+
hist_adapt = adjust_histogram(img, AdaptiveEqualization(nbins = 256, rblocks = 4, cblocks = 4, clip = 0.2))
26+
27+
mosaicview(img, hist_equal, gamma_correction, hist_adapt; nrow = 1)
28+
29+
# --- save covers --- #src
30+
using FileIO #src
31+
save("assets/histogram_equalization.png", hist_equal) #src

0 commit comments

Comments
 (0)