-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from aquatiko/rgb_hsv
added demonstration: RGB to HSV and thresholding
- Loading branch information
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |