Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Shifting RGB values of a single color channel
#1
Hello, 

I’m a weaver and textile maker with no prior coding or programming experience. In researching and reading through posts on this and other message boards, I was able to find a lot of useful information, but nothing that I could clearly map on what it is I’m trying to do. I’m hoping someone can steer me in the right direction. 

I’m working with a set of 18x18 (324px), 8 bit RGB color PNGs which will ultimately be converted into weave structures. I am interested in implementing a script which will allow me to change the value of all pixels of a particular color channel. I’m seeing a number of posts describing how to change the color values of specific pixels, but little about making global changes to the color channels themselves.

I want to be able to manipulate each color channel separately. For example, I'd like to be able to edit all RED pixels in an image such that all R pixel values increase by, say, 2, while pixels containing no R remain unchanged. Additionally, I want to be able to specify a limit, e.g. if the maximum R value in the image is 178, all R pixel values equaling 178 will remain unchanged, while all pixels with R values less than 178 will increase in value by 2. 

I hope to be able to specify the channel (e.g. RED), amount of change (e.g. 2, 1, etc.), type of change (e.g. increase/decrease), and limit (e.g. n = 178, n = 0, n = 255, etc.) as those variables will need to be adjusted to satisfy different color palettes and weave structures.

I've tried achieving this in Photoshop and other graphics editors, but outside of selecting like pixels and adjusting their values manually, I haven't had luck in finding an effective solution for this.
 
I’m wondering 1) how feasible this is, 2) what programming language (Python, Java, etc) might provide the most straightforward, expedient solution and 3) if anybody has any tips about how go about writing a script like this (Script-Fu, OpenCV?) as this is all quite new to me.

Thanks in advance for your help,
TF
Reply
#2
If you have never coded, this is will be an uphill battle. Otherwise any language with some image library will do. Within Gimp you have the choice between C, Script-fu, and Python. C is powerful but hardcore, Script-fu is a bit alien for most people, Python is a popular language. But maybe you can avoid scripting:
  • I assume that in a 18x18 weaving pattern you haven't got that many colors. So you can possibly make your pattern color-indexed and edit the relevant colors in the color map.
  • Or with the conventional tools, for instance to shift up a channel by N:
    • Start the Levels tool
    • Select the color channel at the top
    • Subtract N on the right end if the input
    • Add N to the left end of the output
  •    
    You can do something equivalent with Curves by selecting one channel and setting the output curve to a straight line which is N above the identity diagonal (shift the line up/down at one end, and set the other end to make the line parallel)
This said, adding linear values to 8-bit color channels has no real meaning because these channels are gamma corrected (they don't really represent a linear change for your eyes). In Gimp 2.10 you can work in linear or gamma-corrected spaces.
Reply
#3
Thank you for your reply. Per your suggestions, I was encouraged to rethink how I might use different blend modes to achieve the desired effect and I think I've come up with a working solution.
Reply


Forum Jump: