# Colour jpg images

**URL:** https://discourse.psychopy.org/t/colour-jpg-images/19662
**Category:** Builder
**Created:** [January 15, 2021, 1:11pm UTC](https://discourse.psychopy.org/t/colour-jpg-images/19662 "2021-01-15T13:11:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![hiuwah0130](https://avatars.discourse-cdn.com/v4/letter/h/7cd45c/32.png) [@hiuwah0130](https://discourse.psychopy.org/u/hiuwah0130)
#### Post date: [January 15, 2021, 1:11pm UTC](https://discourse.psychopy.org/t/colour-jpg-images/19662/1 "2021-01-15T13:11:34Z")

</div>

**OS** : masOS catalina  
**PsychoPy version** : 2020.2.6  
**Standard Standalone? (y/n)** If not then what?:  
**What are you trying to achieve?:**  
I would like to colour the foreground or background of some jpg. images with a colour randomly selected from a RGB colour space. Can I know how can I do it in psychoPy? Thanks in advance!

 ![expt1](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/4/f/4f83541bbc9659ce45ddd810b8f2b9a23011a3fe.jpeg)

---

<div class="post-metadata">

### Author: ![tandy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tandy/32/9246_2.png) [@tandy](https://discourse.psychopy.org/u/tandy)
#### Post date: [January 15, 2021, 2:04pm UTC](https://discourse.psychopy.org/t/colour-jpg-images/19662/2 "2021-01-15T14:04:40Z")

</div>

Non coding solution \> just create a lot of different image yourself with different foreground/background colour, feed them to psychopy using and excel file and a loop and let the program manage the randomized presentation of these stimuli.

Coding solution \> I am not sure that what you want to do can be done in psychopy 🤔  
For example, you could “recreate” the image in the example using different polygon components and then use a code component to randomly colour the foreground/background, BUT you’ll have to re-create each image and more complex images would be rather challenging to adapt.

tandy

---

<div class="post-metadata">

### Author: ![hiuwah0130](https://avatars.discourse-cdn.com/v4/letter/h/7cd45c/32.png) [@hiuwah0130](https://discourse.psychopy.org/u/hiuwah0130)
#### Post date: [January 15, 2021, 2:50pm UTC](https://discourse.psychopy.org/t/colour-jpg-images/19662/3 "2021-01-15T14:50:53Z")

</div>

Thanks, Tandy! Yes, I would like to recreate those pictures. I would like to use a code component to randomly colour the foreground/background of different images with an irregular shape in it.

---

<div class="post-metadata">

### Author: ![tandy](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tandy/32/9246_2.png) [@tandy](https://discourse.psychopy.org/u/tandy)
#### Post date: [January 15, 2021, 3:05pm UTC](https://discourse.psychopy.org/t/colour-jpg-images/19662/4 "2021-01-15T15:05:06Z")

</div>

Then you should be able to recreate them with different polygon components. I’m sure there is also a way to randomly selecting a fill colour using a code component. I think you should start with recreating the images and work from there.
