# Copy of Image

**URL:** <https://discourse.julialang.org/t/copy-of-image/99186>\
**Category:** Signal and Image Processing\
**Created:** [May 21, 2023, 6:26pm UTC](https://discourse.julialang.org/t/copy-of-image/99186 "2023-05-21T18:26:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SergeantMike67](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sergeantmike67/32/25103_2.png) [@SergeantMike67](https://discourse.julialang.org/u/SergeantMike67)\
**Post date:** [May 21, 2023, 6:26pm UTC](https://discourse.julialang.org/t/copy-of-image/99186/1 "2023-05-21T18:26:22Z")

</div>

I want to take an image and convert all colors to white leaving only the black pixels. I wrote the following code

using Images

pix=“”

for pixel in pix

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [May 21, 2023, 7:28pm UTC](https://discourse.julialang.org/t/copy-of-image/99186/2 "2023-05-21T19:28:56Z")

</div>

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [May 21, 2023, 8:23pm UTC](https://discourse.julialang.org/t/copy-of-image/99186/3 "2023-05-21T20:23:31Z")

</div>

An interesting guessing game! My guess:

```julia
using Images, TestImages

cat1 = testimage("chelsea")

cat2 = map(p -> Gray(p) > 0.2 ? colorant"white" : 
   colorant"black", cat1)

mosaicview(cat1, cat2)

```

 ![Screenshot 2023-05-21 at 21.19.58](https://global.discourse-cdn.com/julialang/original/3X/6/3/638110c832b4424df639384505e7727c5b021801.png)

You can probably write a better “colour-detecting” function than this though. 🙂

---

<div class="post-metadata">

**Author:** ![SergeantMike67](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sergeantmike67/32/25103_2.png) [@SergeantMike67](https://discourse.julialang.org/u/SergeantMike67)\
**Post date:** [May 23, 2023, 8:40pm UTC](https://discourse.julialang.org/t/copy-of-image/99186/4 "2023-05-23T20:40:33Z")

</div>

> [@cormullion](#):
>
> ```julia
> using Images, TestImages
> 
> cat1 = testimage("chelsea")
> 
> cat2 = map(p -> Gray(p) > 0.2 ? colorant"white" : 
> colorant"black", cat1)
> 
> mosaicview(cat1, cat2)
> 
> ```

Sorry folks, Somehow a partial thought got posted. Not exactly sure how but please ignore.
