Determining "SystemFaceButton" RBG Value At RunTime - python

I am using tkinter and the PIL to make a basic photo viewer (mostly for learning purposes). I have the bg color of all of my widgets set to the default which is "systemfacebutton", whatever that means.
I am using the PIL.Image module to view and rotate my images. When an image is rotated you have to choose a fillcolor for the area behind the image. I want this fill color to be the same as the default system color but I have no idea how to get a the rgb value or a supported color name for this. It has to be calculated by python at run time so that it is consistent on anyone's OS.
Does anyone know how I can do this?

You can use w.winfo_rgb("systembuttonface") to turn any color name to a tuple of R, G, B. (w is any Tkinter widget, the root window perhaps. Note that you had the color name scrambled.) The values returned are 16-bit for some unknown reason, you'll likely need to shift them right by 8 bits to get the 0-255 values commonly used for specifying colors.

Related

Mapping `int` value to color in a color palette

I've made a Python-based simulation that feeds into a 3D modeling program, Rhino for further calculations and to display the results. I'm wanting to color the objects based on a value generated by the simulation, preferably using a color pallet such as Viridis, brewer, etc.
I'm having difficulty finding a module where I can
enter a min/max value for the scale
choose a color palette
give a float value;
and in return, the module would give a specific color relative to that value. I will then break down the color into RGB values to feed into my modeling program.
Does anyone have any suggestions for how to do this? All the color modules I have found so far feed into matplotlib or another graphing library rather than just allowing me to directly give a value and then return a color.
Thanks!

RGB in OpenCV. What does it mean?

Assume we are reading and loading an image using OpenCV from a specific location on our drive and then we read some pixels values and colors, and lets assume that this is a scanned image.
Usually if we open scanned image we will notice some differences between the printed image (before scanning) and the image if we open it and see it on the display screen.
The question is:
The values of the pixels colors that we get from OpenCV. Are they according to our display screen color space or we get exactly the same colors we have in the scanned image (printed version) ??
I am not sure, what you want to do or achieve, here's one thing to mention about color profiles.
The most common color profile for cameras, screens and printers is sRGB, which is a limited color spectrum which does not include the whole RGB range (because the cheap hardware can't visualize it anyways).
Some cameras (and probably scanners) allow to use different color profiles like AdobeRGB, which increases the color space and "allows" more colors.
The problem is, if you capture (e.g. scan) an image in AdobeRGB color profile, but the system (browser/screen/printer) interprets it as sRGB, you'll probably get washed out colors, just because of wrong interpretation (like you'll get blue faces in your image, if you interpret BGR images as RGB images).
OpenCV and many browsers, printers, etc. always interpret images as sRGB images, according to http://fotovideotec.de/adobe_rgb/
As long as you don't change the extension of the image file, the pixel values don't change because they're stored in memory and your display or printer are just the way you want to see the image and often you don't get the same thing because it depends on the technology and different filters applied to you image before they're displayed or printed..
The pixel values are the ones you read in with
imgread
It depends on the flags you set for it. The original image may have a greater bit-depth (depending on your scanner) than the one you loaded.
Also the real file extension is determined from the first bytes of the file, not by the file name extension.
So it may not be the pixel value of the scanned image if the bit-depths differ.
Please have a look at the imgread documentation.

Nuke viewer LUT settings while working on alpha channel

As per my knowledge, LUT is meant to be applied on color channels (RGB) since we are doing colorspace conversion. But Nuke's viewer LUT settings affect alpha channel too. I am aware that viewer LUT doesn't alter original pixel values but only displays them as per the LUT settings set, but shouldn't we turn off viewer LUT while working on alpha channel? Like for instance pulling a key or doing roto ?
Shouldn't we be viewing alpha in linear color space? Am I missing something here?
You're right, NUKE Viewer's LookUp Table doesn't change alpha at all but it affects it. You need to use Viewer's f/8 (multiplier) slider and y (gamma) slider for changing appearance of your alpha when you're keying. NUKE's working color space is LINEAR but default LUT settings for monitor, 8-bit and 16-bit files are superRGB corrected:
Read an article about NUKE colorspaces and color transformations: HERE.
To compensate sRGB gamma for getting linear working color space NUKE uses mirrored gamma:
You can change any default LUT settings or turn off alpha channel (or rgb, or any channel you want) for your convenience at any time.
Execute this code and then create new Viewer node with ctrl-i shortcut (cmd-i on a Mac):
import nuke
# to change Viewers' properties globally
nuke.knobDefault('Viewer.channels', 'rgb')
nuke.knobDefault('Viewer.viewerProcess', 'rec709') # use rec709, for instance
You'll get this:
Or simply execute the code for Viewer1, changing viewerProcess for None (linear color space):
nuke.toNode('Viewer1').knob('channels').setValue('alpha')
nuke.toNode('Viewer1').knob('viewerProcess').setValue('None')
# then add these 3 lines to menu.py file (they'll work after restart)
nuke.knobDefault("Root.monitorLut", "linear") # monitor LUT
nuke.knobDefault("Root.int8Lut", "linear") # 8-bit files LUT
nuke.knobDefault("Root.int16Lut", "linear") # 16-bit files LUT
Additionally, to physically transform you current LUT, you can use OpenColorIO LUT and 3D LUT nodes from Color Toolbar's menu.
And a few words about Pixel Analyzer panel:
Current, Min, Max, Average and Median operations in Pixel Analyzer panel are applied to any channels from dropdown menu. If you need only alpha value or only rgb values just choose it from the menu.
But. There's no mistake if you'll be using rgba mode. Check it. Apply Keyer node to the image and you'll see RGB values are the same with or without alpha (but only if rgba isn't premultiplied).
And it's sad but there still isn't access to API via Python for the Pixel Analyzer panel.

Python (pygame): Get image color information?

My end goal is to find a color in an image (in this case white) and replace it with another color (based on certain circumstances). So, as a certain variable changes the white is replaced with a specific color.
However, to get there I'm currently just playing with images (using tutorials ..etc). I'm trying to use the below code to print the color palette of an image. My understanding is the colors are a "tuple" of 3 integer representing RGB. 0 = darkest, 255 = white. So, the image I'm testing is a black and white image. I'm expecting something like "(0,0,0),(255,255,255)". So, I figured if I could get this far, then I could write a code to replace the "(255,255,255)" with the appropriate color.
I mentioned the end goal because I'm very aware that my approach might not be the best, and that perhaps someone has a better way I can go about this. If not, I'd at least like to be able to print a string referencing the colors an image contains. The "NOFRAME" was a great piece of advice I found on this site, as I'm not actually "using" the images/graphics - just using their attributes.
image1=r"C:\Python27\Lib\site-packages\pygame\examples\data\image1.jpg"
image2=r"C:\Python27\Lib\site-packages\pygame\examples\data\image2.png"
import pygame, sys
from pygame.locals import *
pygame.init()
pygame.display.set_mode((1,1), pygame.NOFRAME)
background = pygame.image.load(image1).convert()
mouse_c=pygame.image.load(image2).convert_alpha()
colorpal = pygame.Surface.get_palette(mouse_c)
print colorpal
What you want to do is going to require a lot of pixel level work, so I recommend that you use a pygame.PixelArray object for direct pixel access of the surface(s).
For what you specifically want to do, it sounds like you could use the pygame.PixelArray.replace() method.
You can get individual pixels on image surfaces by using theget_atmethod of Pygame surfaces - as inmouse_c.get_at((0,0)).
This is strictly what you are asking for -- but it won't suit any real world needs, as it is extremely, and I am saying extremely, slow to process all pixels of an image calling just this.
You could take the image buffer withget_bufferand interpret the data there, raw, or pass the buffer along to a function written in native code to get some speed.
Still, if your goal is to replace a color by another in real time you can resort to use indexed images - that way, each image will have a color table, you just modify,say, the color number 10 to be 0,0,255, and as you render the image, all occurrences of that color become blue. This is fast -- not as efficient as back in the 8 bit video-games time when this was done by hardware -- but it will be orders of magnitude faster any substitutions you try to make in pure Python code.

Change the color of a pixel in a canvas, Tkinter, Python

Someone know if it's possible to change the color of a pixel in a canvas without using un object, so without using something like canvas.create_oval or canvas.create_rectangle ?
There is no way to color a pixel other than to create a 1x1 pixel object of some sort. And yes, at some point you will experience performance problems. The canvas simply wasn't designed to be used this way.
If you're really needing to create a large area in which you can manage individual pixels, you can create a canvas with a single image that is the same size as the canvas. You can then set the color of individual pixels on the image through the photo image interface.
Within tkinter itself, it's impossible.
Even if you manage to change a pixel on canvas window (which is possible with X11 and Windows APIs in a platform-dependent way), you'd have to ensure it's repainted properly.
You can, of course, place a frame of size 1x1 over the canvas, with a background color you want. This way, pixel is "changed" and no canvas object is created. If there's a real (though strange) problem behind a question, this trick could be a solution.

Categories