Skip to content

Commit

Permalink
Merge pull request #42 from aquatiko/rgb_hsv
Browse files Browse the repository at this point in the history
added demonstration: RGB to HSV and thresholding
  • Loading branch information
Evizero committed Jan 25, 2019
2 parents 5ea787d + 8e9a7fd commit 1816ae1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ makedocs(format = :html,
"Demos" => Any[
"demos.md",
"demos/color_separations_svd.md",
"demos/rgb_hsv_thresholding.md",
],
"function_reference.md",
"api_comparison.md",
Expand Down
Binary file added docs/src/assets/demos/rgb_hsv_thresholding.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions docs/src/demos.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@
</div>
```

```@raw html
<div class="card-200">
<div class="card-img">
```
[![rgb_hsv_thresholding](assets/demos/rgb_hsv_thresholding.png)](@ref rgb_hsv_thresholding)
```@raw html
</div>
<div class="card-text">
```
[RGB to HSV and thresholding](@ref rgb_hsv_thresholding)
```@raw html
</div>
</div>
```

```@raw html
</div>
```
Expand Down
38 changes: 38 additions & 0 deletions docs/src/demos/rgb_hsv_thresholding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# [RGB to HSV and thresholding](@id rgb_hsv_thresholding)

This example illustrates how RGB to HSV (Hue, Saturation, Value) conversion
can be used to facilitate segmentation processes.
A simple segmentation of the image can then be effectively performed
by a mere thresholding of the HSV channels.


```julia
using Images, TestImages, LinearAlgebra, Interact, ImageView

rbg_img = testimage("lighthouse")
hsv_img = HSV.(rbg_img)
channels = float(channelview(hsv_img))

hue_img = channels[1,:,:]
value_img = channels[3,:,:]
saturation_img = channels[2,:,:]
binary_img = zeros(size(hue_img))
@manipulate for hue in 0:255, saturation in 0:255, value in 0:255
fill!(binary_img, 0.0)
for ind in eachindex(hue_img)
if hue_img[ind] <= hue && saturation_img[ind] <= saturation/255 && value_img[ind] <= value/255
binary_img[ind] = 1
end
end
colorview(Gray, binary_img)
end
```

Here's the result in IJulia:

![lighthouse](../assets/demos/rgb_hsv_thresholding.png)

You can click on the slider bars to change the threshold
of hue, saturation and value.
The obtained binary image can be used as a mask on the
original RGB image.

0 comments on commit 1816ae1

Please sign in to comment.