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

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.

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)?

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:

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.”

1 Like

You can check the quickstart section of the documentation: Quickstart · JuliaImages

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

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

Catch-and-release anonymised!

1 Like