# Modifying a rectangle from an image and replacing the original rectangle with the modified one

**URL:** <https://discourse.julialang.org/t/modifying-a-rectangle-from-an-image-and-replacing-the-original-rectangle-with-the-modified-one/66711>\
**Category:** New to Julia\
**Created:** [August 20, 2021, 6:57am UTC](https://discourse.julialang.org/t/modifying-a-rectangle-from-an-image-and-replacing-the-original-rectangle-with-the-modified-one/66711 "2021-08-20T06:57:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![banksiaboy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/banksiaboy/32/27032_2.png) [@banksiaboy](https://discourse.julialang.org/u/banksiaboy)\
**Post date:** [August 20, 2021, 6:57am UTC](https://discourse.julialang.org/t/modifying-a-rectangle-from-an-image-and-replacing-the-original-rectangle-with-the-modified-one/66711/1 "2021-08-20T06:57:59Z")

</div>

I have a rectangular subset of an image which I’ve done some processing on, I want to put the modified subset into exactly the same spot in the original image.  
I am struggling to find the Julia vocabulary to search in the docs.

```julia
c1, c2 = (5:23,17:30)
sub_image = image[c1,c2]
result = do_messy_stuff(sub_image)

```

How do I assign the result back to `image[c1,c2]`?

Also, and separately, can I assign back to a view as if `sub-image = view(image, c1,c2)`?

---

<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:** [August 20, 2021, 9:08am UTC](https://discourse.julialang.org/t/modifying-a-rectangle-from-an-image-and-replacing-the-original-rectangle-with-the-modified-one/66711/2 "2021-08-20T09:08:05Z")

</div>

You can do `image[c1, c2] = result`

> can I assign back to a view as if `sub-image = view(image, c1,c2)`

You mean, use the view to assign back to the parent? Yes, like this:

```julia
sub_image .= result

```

The latter means "assign every element in `sub_image` the corresponding value in `result` whereas `sub_image = result` means “throw away whatever `sub_image` used to refer to and have it refer to `result` instead.”

---

<div class="post-metadata">

**Author:** ![JohnnyChen94](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnnychen94/32/29979_2.png) [@JohnnyChen94](https://discourse.julialang.org/u/JohnnyChen94)\
**Post date:** [August 20, 2021, 11:09am UTC](https://discourse.julialang.org/t/modifying-a-rectangle-from-an-image-and-replacing-the-original-rectangle-with-the-modified-one/66711/3 "2021-08-20T11:09:19Z")

</div>

You can check the quickstart section of the documentation: [Quickstart · JuliaImages](https://juliaimages.org/stable/tutorials/quickstart/#Images-are-just-arrays)

This depends on how you write the codes:

- If `result === sub_image` and `sub_image` is a view (e.g., from `view(image, c1, c2)`), then you don’t need to assign back
- Otherwise, `image[c1, c2] .= result`

---

<div class="post-metadata">

**Author:** ![banksiaboy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/banksiaboy/32/27032_2.png) [@banksiaboy](https://discourse.julialang.org/u/banksiaboy)\
**Post date:** [August 20, 2021, 11:43pm UTC](https://discourse.julialang.org/t/modifying-a-rectangle-from-an-image-and-replacing-the-original-rectangle-with-the-modified-one/66711/4 "2021-08-20T23:43:48Z")

</div>

Thank-you both very much.  
Adjusting my understanding of broadcasting…  
Such a joy to be using a ‘designed’ language!

---

<div class="post-metadata">

**Author:** ![banksiaboy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/banksiaboy/32/27032_2.png) [@banksiaboy](https://discourse.julialang.org/u/banksiaboy)\
**Post date:** [August 21, 2021, 12:05am UTC](https://discourse.julialang.org/t/modifying-a-rectangle-from-an-image-and-replacing-the-original-rectangle-with-the-modified-one/66711/5 "2021-08-21T00:05:05Z")

</div>

Catch-and-release anonymised!

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/8/b89934d40da140500715aa9f006c4e51bf01af92.jpeg)
