# Conversion to Gray{Bool}

**URL:** <https://discourse.julialang.org/t/conversion-to-gray-bool/50572>\
**Category:** New to Julia\
**Created:** [November 22, 2020, 7:31am UTC](https://discourse.julialang.org/t/conversion-to-gray-bool/50572 "2020-11-22T07:31:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ashwani\_Rathee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashwani_rathee/32/49551_2.png) [@Ashwani\_Rathee](https://discourse.julialang.org/u/Ashwani_Rathee)\
**Post date:** [November 22, 2020, 7:31am UTC](https://discourse.julialang.org/t/conversion-to-gray-bool/50572/1 "2020-11-22T07:31:13Z")

</div>

I wish to convert of type(which i loaded as a bitmap)(I tried other types before)  
`Array{ColorTypes.RGB{FixedPointNumbers.Normed{UInt8,8}},2} to an object of type ColorTypes.Gray{Bool}`  
I wanted to apply convex hull algorithm but when I load images it gave me various type of errors:

```julia
MethodError: no method matching convexhull(::Array{ColorTypes.RGB{FixedPointNumbers.Normed{UInt8,8}},2})
Closest candidates are:

convexhull(!Matched::AbstractArray{T,2}) where T<:Union{ColorTypes.Gray{Bool}, Bool} at /home/ashwani/.julia/packages/ImageMorphology/BZPyk/src/convexhull.jl:7

```

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [November 22, 2020, 8:24am UTC](https://discourse.julialang.org/t/conversion-to-gray-bool/50572/2 "2020-11-22T08:24:18Z")

</div>

I assume you mean you want to convert the _elements_ of the array from `RGB{N0f8}` to `Gray{Bool}`, rather than convert the entire array to a single `Gray(true)`/`Gray(false)` value.

You’ll need to decide _how_ to convert to a binary image; there’s no unique answer. The most common way to convert from RGB to grayscale is based on perceptual intensity; we have a demo of that in [https://juliaimages.org/latest/democards/examples/color\_channels/rgb\_grayscale/#RGB-to-GrayScale](https://juliaimages.org/latest/democards/examples/color_channels/rgb_grayscale/#RGB-to-GrayScale). But of course you could do that based on, say, just the red channel, or the distance from a given pixel to the nearest blue-dominated pixel, etc. The number of ways is literally infinite depending on your goal.

`Gray.(img)` would convert to a `Gray{N0f8}`, which still isn’t binary. Continuing the theme of using the intensity, here’s a method based on thresholding:

```julia
julia> using Images, TestImages

julia> img = testimage("lighthouse");

julia> imgg = Gray.(img);

julia> thresh = otsu_threshold(imgg)
Gray{N0f8}(0.408)

julia> imgt = imgg .> thresh;

julia> summary(imgt)
"512×768 BitMatrix"

```

But again, the number of ways you could binarize is infinite, so you’ll have to decide what you actually want.
