diff --git a/docs/make.jl b/docs/make.jl index 119bc718..0ba26631 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -21,7 +21,11 @@ makedocs(format = :html, "Demos" => Any[ "demos.md", "demos/color_separations_svd.md", - "demos/rgb_hsv_thresholding.md", + + "demos/contrast_brightness_histogram.md", + + "demos/rgb_hsv_thresholding.md", + ], "function_reference.md", "api_comparison.md", diff --git a/docs/src/assets/demos/histogramEq/brightHist.jpg b/docs/src/assets/demos/histogramEq/brightHist.jpg new file mode 100644 index 00000000..cc93ce57 Binary files /dev/null and b/docs/src/assets/demos/histogramEq/brightHist.jpg differ diff --git a/docs/src/assets/demos/histogramEq/darkHist.jpg b/docs/src/assets/demos/histogramEq/darkHist.jpg new file mode 100644 index 00000000..f212acdd Binary files /dev/null and b/docs/src/assets/demos/histogramEq/darkHist.jpg differ diff --git a/docs/src/assets/demos/histogramEq/darkimage.png b/docs/src/assets/demos/histogramEq/darkimage.png new file mode 100644 index 00000000..b6569fc6 Binary files /dev/null and b/docs/src/assets/demos/histogramEq/darkimage.png differ diff --git a/docs/src/assets/demos/histogramEq/eqhist.jpg b/docs/src/assets/demos/histogramEq/eqhist.jpg new file mode 100644 index 00000000..878f5b8f Binary files /dev/null and b/docs/src/assets/demos/histogramEq/eqhist.jpg differ diff --git a/docs/src/assets/demos/histogramEq/highHist.jpg b/docs/src/assets/demos/histogramEq/highHist.jpg new file mode 100644 index 00000000..9c5668a4 Binary files /dev/null and b/docs/src/assets/demos/histogramEq/highHist.jpg differ diff --git a/docs/src/assets/demos/histogramEq/highcontrast.png b/docs/src/assets/demos/histogramEq/highcontrast.png new file mode 100644 index 00000000..9c3171e0 Binary files /dev/null and b/docs/src/assets/demos/histogramEq/highcontrast.png differ diff --git a/docs/src/assets/demos/histogramEq/lightimage.png b/docs/src/assets/demos/histogramEq/lightimage.png new file mode 100644 index 00000000..ca91f3e5 Binary files /dev/null and b/docs/src/assets/demos/histogramEq/lightimage.png differ diff --git a/docs/src/assets/demos/histogramEq/lowHist.jpg b/docs/src/assets/demos/histogramEq/lowHist.jpg new file mode 100644 index 00000000..ddceef29 Binary files /dev/null and b/docs/src/assets/demos/histogramEq/lowHist.jpg differ diff --git a/docs/src/assets/demos/histogramEq/lowcontrast.png b/docs/src/assets/demos/histogramEq/lowcontrast.png new file mode 100644 index 00000000..99ebda13 Binary files /dev/null and b/docs/src/assets/demos/histogramEq/lowcontrast.png differ diff --git a/docs/src/demos.md b/docs/src/demos.md index b71524e8..24683ea5 100644 --- a/docs/src/demos.md +++ b/docs/src/demos.md @@ -11,6 +11,7 @@
``` [![svd](assets/demos/color_separations_svd.jpg)](@ref color_separations_svd) + ```@raw html
@@ -19,6 +20,24 @@ ```@raw html
+ +``` + +```@raw html +
+
+``` +[![con_bright_hist](assets/demos/histogramEq/highHist.jpg)](@ref contrast_brightness_histogram) + +```@raw html +
+
+``` +[Contrast and Brightness histograms](@ref contrast_brightness_histogram) +```@raw html +
+
+ ``` ```@raw html @@ -40,6 +59,7 @@ ``` + ## Contributions Users are invited to [contribute demonstrations of their own](https://github.com/JuliaImages/juliaimages.github.io). diff --git a/docs/src/demos/contrast_brightness_histogram.md b/docs/src/demos/contrast_brightness_histogram.md new file mode 100644 index 00000000..18ea430e --- /dev/null +++ b/docs/src/demos/contrast_brightness_histogram.md @@ -0,0 +1,104 @@ +# [Contrast and brightness analysis using histograms] (@id contrast_brightness_histogram) + +This demonstration will give you an idea on how to analyse and enhance the contrast and brightness of any image. We are using (Number of pixels vs. Pixel intensity) histogram of an +image. +For this demo you can download the images from [here](https://drive.google.com/open?id=1xoqiDgO3FCHqzKFaL0TOa45GiBgzuwbU). + +Ofcourse, a dark image and a bright image are visually different. +But, here, to appreciate the difference we will draw their respective histograms and observe the characterstics. +For example consider the below images - + +``` julia +using Images, ImageView, FileIO + +darkImg = load("histogramEq/darkimage.png") +brightImg = load("histogramEq/lightimage.png") + +imshow(darkImg) +imshow(brightImg) +``` +**Note : In case of error, try importing ImageMagick library before Images library.** + +| ![DI](../assets/demos/histogramEq/darkimage.png) | ![BI](../assets/demos/histogramEq/lightimage.png) | +|:------:|:---:| +| Dark | Bright | +Also, there can be some instances when we need a seperation mechanism for high +contrast image and a low contrast image in a code. + +``` julia +using Images, ImageView, FileIO + +highConImg = load("histogramEq/highcontrast.png") +lowConImg = load("histogramEq/lowcontrast.png") + +imshow(highConImg) +imshow(lowConImg) +``` + +| ![HC](../assets/demos/histogramEq/highcontrast.png) | ![LC](../assets/demos/histogramEq/lowcontrast.png) | +|:------:|:---:| +| High Contrast | Low Contrast | +Analysing histograms may help in such seperations also. + + +Let's have a look at the histograms of these images - +```julia +function plotHist(image) + + hist = imhist(image) + + column = maximum(hist[2]) + row = length(hist[1]) + 1 + img = fill(0, (column, row)) + + j = 0 + for i in hist[2] + for k in size(img)[1]- i + 1:size(img)[1] + img[k, j] = 1 + end + j = j + 1 + end + return img +end + +# to plot the histogram for dark image +img = plotHist(darkImg) +img = Gray.(img) +imshow(img) +``` + +| ![HC](../assets/demos/histogramEq/highHist.jpg) | ![LC](../assets/demos/histogramEq/lowHist.jpg) | +|:------:|:---:| +| High contrast | Low contrast | + +So, it may be noted from above that high contrast images have **roughly** +two distinct peaks in their histogram i.e., the foreground and +background can be said to be concentrated around two different intensities. More distinct +the peaks are more is the image contrast. + +| ![DI](../assets/demos/histogramEq/darkHist.jpg) | ![BI](../assets/demos/histogramEq/brightHist.jpg) | +|:------:|:---:| +| Dark image | Bright image | +Also, on observing the histograms for bright and dark image, we observe that +in the case of bright images the intensity is **roughly** concentrated in the high intensity region. +While, in the case of a dark image, the intensity is **roughly** concentrated in the low intensity region. + +Histograms can be very useful in many applications. One such use is described below. +We can enhance a low contrast image by using **Histogram Equalisation** method. +This method spreads out the most frequent intensity values in an image. + +``` julia +# equalising the low contrast image +equalised_img = histeq(lowConImg, 256) # 256 is the number of bins +imshow(equalised_img) +``` +| ![HE](../assets/demos/histogramEq/eqhist.jpg) | +|:------:| +| Enhanced image | + + + + + + +