# Rank of admission and subtraction

**URL:** <https://discourse.julialang.org/t/rank-of-admission-and-subtraction/25065>\
**Category:** General Usage\
**Created:** [June 8, 2019, 3:33am UTC](https://discourse.julialang.org/t/rank-of-admission-and-subtraction/25065 "2019-06-08T03:33:02Z")\
**Posts on this page:** 4\
**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:** [June 8, 2019, 3:33am UTC](https://discourse.julialang.org/t/rank-of-admission-and-subtraction/25065/1 "2019-06-08T03:33:02Z")

</div>

How could you define the range in admission and subtraction over an image?

enter (0-255) without going past 255 or reducing me from 0.

my code is something like this …

```julia
#=
admiminsion and subtracion
=#
R₁ = float.(imggₗ) + float.(imggₑ)

R₂ = R₁ - float.(imggₑ)

# imggₗ + imggₗ + imggₑ.
R₃ = R₁ + R₂

```

but there the error is that I’m taking float values …

how could I do it to establish the range (0-255).

help me…!

---

<div class="post-metadata">

**Author:** ![magister-ludi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/magister-ludi/32/4003_2.png) [@magister-ludi](https://discourse.julialang.org/u/magister-ludi)\
**Post date:** [June 8, 2019, 11:31am UTC](https://discourse.julialang.org/t/rank-of-admission-and-subtraction/25065/2 "2019-06-08T11:31:45Z")

</div>

You probably want to look at [clamp](https://docs.julialang.org/en/v1/base/math/#Base.Math.clamp) or [clamp!](https://docs.julialang.org/en/v1/base/math/#Base.Math.clamp!) depending on whether you want to create a new array, or overwrite the input array. If you use clamp, you will need the broadcast version:

```julia
clamp.(input_array, lovalue, highvalue)

```

It will operate on floating point values without a problem.

---

<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:** [June 8, 2019, 12:52pm UTC](https://discourse.julialang.org/t/rank-of-admission-and-subtraction/25065/3 "2019-06-08T12:52:48Z")

</div>

but how can I use int values and define approximation ranges (0-255)?

and do not use float values …

---

<div class="post-metadata">

**Author:** ![magister-ludi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/magister-ludi/32/4003_2.png) [@magister-ludi](https://discourse.julialang.org/u/magister-ludi)\
**Post date:** [June 9, 2019, 11:17am UTC](https://discourse.julialang.org/t/rank-of-admission-and-subtraction/25065/4 "2019-06-09T11:17:59Z")

</div>

I’m making lots of assumptions here, based on your question in this and other posts. If I’m wrong, let me know, and I’ll try to correct what I’ve written below.

It looks like you’re trying to manipulate images. You’ve converted the image pixels to floating point values so that you can do arithmetic that doesn’t wrap around. You then want to change the pixels that are outside the normal range. In Julia, the range of values for image pixels is 0-1, so you probably want to clamp the pixels to those values.

```julia
# Result of arithmetic is R3, which is floating point
R₃ = R₁ + R₂
# Clamp the data to 0-1
Rclamped = clamp.(R₃, 0.0, 1.0)
# Rclamped has valid pixel range, convert to image data
Routput = Gray{N0f8}.(Rclamped)
# Routput is now a valid image. It will display
# correctly in Juno or Jupyter, and can be saved
# to a standard image format using save()

```
