# Change image color

**URL:** <https://discourse.processing.org/t/change-image-color/12685>\
**Category:** Coding Questions\
**Created:** [July 12, 2019, 2:18pm UTC](https://discourse.processing.org/t/change-image-color/12685 "2019-07-12T14:18:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![The\_nish](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/the_nish/32/5634_2.png) [@The\_nish](https://discourse.processing.org/u/The_nish)\
**Post date:** [July 12, 2019, 2:18pm UTC](https://discourse.processing.org/t/change-image-color/12685/1 "2019-07-12T14:18:13Z")

</div>

i have 2 images a and b which is listed below. my both images are in rgb format . i want to change color of “b” image like “a” image by processing. tell me how it is possible.

 ![a](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/57eb0240468c3400ebf6459d3299c13f9eda243b.jpeg) ![b](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/393f149fc59cdcbf2033c3b248ac535ae8211c5e.jpeg)

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [July 12, 2019, 2:33pm UTC](https://discourse.processing.org/t/change-image-color/12685/2 "2019-07-12T14:33:11Z")

</div>

if the question is more general like:

if there is pixels with color black in image a,  
change image b same pixels to black.  
that would be like superimpose  
and there it would not matter that there is a red “A” in image b.

but as more i think about that it makes less sense.

anyhow start loading the images,  
read the color of image a  
in a for loop over all pixels and use  
[https://processing.org/reference/get\_.html](https://processing.org/reference/get_.html)

now post your running code here for the next step.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 12, 2019, 3:15pm UTC](https://discourse.processing.org/t/change-image-color/12685/3 "2019-07-12T15:15:07Z")

</div>

Start here:

> **[Welcome to Processing!](https://processing.org/)**
>
> Processing is a flexible software sketchbook and a language for learning how to code. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology…

> [Tutorials / Processing.org](https://processing.org/tutorials/)
> 
> > [Color / Processing.org](https://processing.org/tutorials/color/)  
> > [Images and Pixels / Processing.org](https://processing.org/tutorials/pixels/)

> [Reference / Processing.org](https://processing.org/reference/)  
> [Examples / Processing.org](https://processing.org/examples/)

There are examples in the Processing software also.

🙂

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 12, 2019, 3:29pm UTC](https://discourse.processing.org/t/change-image-color/12685/4 "2019-07-12T15:29:39Z")

</div>

It is important to understand the image type that one is working with.

> **[JPEG](https://en.wikipedia.org/wiki/JPEG)**
>
> JPEG (/ˈdʒeɪpɛɡ/ JAY-peg) is a commonly used method of lossy compression for digital images, particularly for those images produced by digital photography. The degree of compression can be adjusted, allowing a selectable tradeoff between storage size and image quality. JPEG typically achieves 10:1 compression with little perceptible loss in image quality.
> JPEG compression is used in a number of image file formats. JPEG/Exif is the most common image format used by digital cameras and other phot...

  
“JPEG is not well suited for line drawings and other textual or iconic graphics, where the sharp contrasts between adjacent pixels can cause noticeable artifacts.”

This is what I get when I fill colours with Paint (Microsoft application):  
 ![a](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/c5b78793fbef2f6b87d2bdd9338a857a69b7db7f.jpeg)  
 ![b](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/b82cd12d7c50063322604474cfb97f1018fde865.jpeg)

🙂

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [July 12, 2019, 4:29pm UTC](https://discourse.processing.org/t/change-image-color/12685/5 "2019-07-12T16:29:00Z")

</div>

Yes very correct ! But OP seems to be using only two very distinctive colors so should be ok !

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [July 12, 2019, 4:56pm UTC](https://discourse.processing.org/t/change-image-color/12685/6 "2019-07-12T16:56:01Z")

</div>

Don’t bet on it - that’s one of the worst case scenarios.
