# How to make a Clipping of an image in Julia

**URL:** <https://discourse.julialang.org/t/how-to-make-a-clipping-of-an-image-in-julia/21756>\
**Category:** General Usage\
**Created:** [March 11, 2019, 9:07pm UTC](https://discourse.julialang.org/t/how-to-make-a-clipping-of-an-image-in-julia/21756 "2019-03-11T21:07:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GERSON\_EZEQUIEL\_HERN](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gerson_ezequiel_hern/32/7437_2.png) [@GERSON\_EZEQUIEL\_HERN](https://discourse.julialang.org/u/GERSON_EZEQUIEL_HERN)\
**Post date:** [March 11, 2019, 9:07pm UTC](https://discourse.julialang.org/t/how-to-make-a-clipping-of-an-image-in-julia/21756/1 "2019-03-11T21:07:13Z")

</div>

how to make a Clipping of an image in Julia

When you have a grayscale image, it is quantized to one byte.  
(I would like to do it with a color image such as the mandrill)

That means that only 255 bts can be quantified and can not be exceeded or have negative values.  
Clipping = set limits of the quantification between 0 and 255  
yes x \<0 yes x\> 255  
x == 0 x == 255

---

<div class="post-metadata">

**Author:** ![danilo-bc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danilo-bc/32/19590_2.png) [@danilo-bc](https://discourse.julialang.org/u/danilo-bc)\
**Post date:** [November 19, 2021, 8:01pm UTC](https://discourse.julialang.org/t/how-to-make-a-clipping-of-an-image-in-julia/21756/2 "2021-11-19T20:01:08Z")

</div>

I think that’s a great question. There’s probably a “one-line” way to do it, but I did it in two lines.

Suppose `a` is your image matrix:

```julia
a = [-230, 1, 260, 5]
a = map(x -> x > 255 ? 255 : x, a)
a = map(x -> x < 0 ? 0 : x, a)

```

`map` takes a function (in this case, an anonymous function) and applies it to the container passed as second argument (`a`).
