# Drawing with color on Grayscale images

**URL:** <https://discourse.julialang.org/t/drawing-with-color-on-grayscale-images/21217>\
**Category:** General Usage\
**Tags:** images, colors\
**Created:** [February 26, 2019, 3:49pm UTC](https://discourse.julialang.org/t/drawing-with-color-on-grayscale-images/21217 "2019-02-26T15:49:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rand5](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rand5/32/867_2.png) [@rand5](https://discourse.julialang.org/u/rand5)\
**Post date:** [February 26, 2019, 3:49pm UTC](https://discourse.julialang.org/t/drawing-with-color-on-grayscale-images/21217/1 "2019-02-26T15:49:48Z")

</div>

I have a grayscale image and I’d like to be able to draw a colored polygon on it with ImageDraw but am running into an error. Here is a MWE:

```julia
using TestImages, ImageDraw, Colors
img = testimage("cameraman")
draw(img,Polygon([(1,1),(30,1),(50,1),(30,30)]),colorant"indianred")

```

I suspect this is because the image is grayscale but the polygon is colored. If this is the case, is there a way around this that doesn’t involve converting the grayscale image to another colorspace?

error is

```julia
MethodError: no method matching draw!(::Array{Gray{FixedPointNumbers.Normed{UInt8,8}},2}, ::Polygon, ::RGB{FixedPointNumbers.Normed{UInt8,8}})
Closest candidates are:
  draw!(::AbstractArray{T<:Colorant,2}, ::Polygon, !Matched::T<:Colorant) where T<:Colorant at C:\Users\C7045\.julia\packages\ImageDraw\OAT7P\src\paths.jl:32
  draw!(::AbstractArray{T<:Colorant,2}, ::Drawable) where T<:Colorant at C:\Users\C7045\.julia\packages\ImageDraw\OAT7P\src\core.jl:137
  draw!(::AbstractArray{T<:Colorant,2}, !Matched::Point, !Matched::T<:Colorant) where T<:Colorant at C:\Users\C7045\.julia\packages\ImageDraw\OAT7P\src\core.jl:176

```

---

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [February 26, 2019, 9:04pm UTC](https://discourse.julialang.org/t/drawing-with-color-on-grayscale-images/21217/2 "2019-02-26T21:04:25Z")

</div>

> [@rand5](#):
>
> I have a grayscale image and I’d like to be able to draw a colored polygon on it /…/ that doesn’t involve converting the grayscale image to another colorspace

What type are you hoping `draw` to return? Why is it not an option to do `draw!(convert.(RGB, img), ...`?

---

<div class="post-metadata">

**Author:** ![rand5](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rand5/32/867_2.png) [@rand5](https://discourse.julialang.org/u/rand5)\
**Post date:** [February 27, 2019, 1:26pm UTC](https://discourse.julialang.org/t/drawing-with-color-on-grayscale-images/21217/3 "2019-02-27T13:26:48Z")

</div>

I have a large number of large grayscale images and was hoping to avoid that for efficiency purposes, but after looking into the definition of `draw`, it looks like it is unavoidable since it is overwriting the color information in `img` itself as opposed to displaying a polygon over `img`.
