CSLUG - Central South LabVIEW User Group (UK)

cancel
Showing results for 
Search instead for 
Did you mean: 

Ideas for automatically selecting a suitable background for user selected colours.

I've a non-critical problem in one of the systems I'm working on at the moment and thought I'd try you guys for ideas before going to the main forum. Let me know if you think this isn't the place.

I'm working on a controller for a printing system, and the ink colours used on the design under print are dynamically displayed. The problem is that the chart backgrounds and button text often disappear when the foreground colour is not distinct from the background. The users are allowed ot pick any colour from the Colour Box.

I've written a simple utility that splits the U32 colour down to x3 U8 RGB, thresholds each somewhere in the middle (based on trial and error) and decides if the background  and text is dark or light. Very simple. But it doesn't work well on white, light grey, yellows and creams.

Can any one suggest a method to get this improved. I don't have Vision toolkit available in this Application, but happy if someone points me to a built in function that does this. I'm intentionally not posted a snippet to see what other people come up with.

As you can see, this is not at all a big issue, as doesn't effect the control in any way, but I thought it would be fun to see what others suggest on this one. Perhaps others could post a few simple brain-teasers?

Lucy

0 Kudos
Message 1 of 8
(7,403 Views)

Hi Lucy,

I don't think I understand your problem properly without seeing an example image but these links might help you.

http://24ways.org/2010/calculating-color-contrast/

http://en.wikipedia.org/wiki/YIQ

From what I understand by this method is that the text is either black or white depending on the colour of the background. The best contrast is used to decide if the text should be black or white.

I have written this vi with two colour boxes, one to choose a colour and then one to display the colour contrast. I am changing the background to the colour chosen, I thought that it might work to change the background to the inverse of the colour chosen but need to do some more research on how to calculate the colour inverse.

Untitled.png

Hope this helps in the mean time.

Greg

Message 2 of 8
(5,502 Views)

Thanks Greg,

It'll be interesting to compare the two methods, I started with using 127 as the threshold but it was better lower, I see you have blue different too. It works well mostly but isn't very good on some composite colours - and doesn't work on pure white.

To confirm use, I'm either colouring a button with Text visible, or plotting on a bar chart. Snippet shows this. On the chart I find black and white too harsh a background so select light and dark grey as the contrasting colours.

It basically works, but users can be fussy and it would be nice to find an elegant solution to this - that works on all colours. On this example green the bar chart is fine but the button text would be better black. So contrast calculation may have to depend on the use.

By the way, if this bar chart style drew an outline around the plot it wouldn't be so much of an issue!

Background selection code.PNG

0 Kudos
Message 3 of 8
(5,502 Views)

Hi Lucy

When you know the trick it is relatively easy. Working with Red, Green and Blue is hard. If you move to Hue, Saturation and Intensity it becomes simple. Hue is what colur red through green to blue. Saturation is how much of that colour and intensity is how light or dark it is. With each of these values you add half the maximum. We normally work on 8 bit, so add 127 and mod it with 255. This means that it is the opposite of what it was before. I tried this out with two VIs from the Vision Module to make sure I wasn't nuts.

This works pretty well, you may need to play with the offset for Hue to make the pallette more acceptable.

Contrast.png

I know that you said you don't have vision, but the algorithms for converting to and from are well documented online. (No time at the moment otherwise I would have done it) Have a play with this and see what you think

Mike

0 Kudos
Message 4 of 8
(5,502 Views)

OK, I had a further play around and remembered the BitMan library in VIPM has the relevant conversion routines. The are 1 based so add 0.5 and mod by 1 to get the same effect without the Vision Development Module.

Contrastv2.png

And I tidied it up a bit too

Mike

Message 5 of 8
(5,502 Views)

Thanks Mike,

I'll try it tomorrow - I may need to restrict the background colours it selects but its a good start.

Just having 'fun' getting the GUI translated into Turkish now, and they've given me Unicode files...... If you know any useful localisation toolkits for simple text  conversion that would be great. I've tried to use icons instead of text to avoid having different language versions but that text keeps sneaking in. I'll post a new question on the forum if I get stuck.

Happy to get involved in discussing other little problems if people post here. Some how its less scary then going on the general forums..., and if we get a good discussion can it go on the agenda on the next meeting at Newbury?

Lucy

0 Kudos
Message 6 of 8
(5,502 Views)

For localisation I only know of this one

http://sine.ni.com/nips/cds/view/p/nid/209037

On the tools network from SEA, it costs but if you are spending time on it that costs too. Try posting on the UI community group I think they have discussed this in the past.

As for running things like this past the User Group that would be great, I may even steal the idea for the CLD Summit. Someone has already suggested a "Hackathon" but if we made a half hour session on the problem presentations and then give everyone an hour to disappear into the groups that interest them and then come back and present solutions. It would be a bit too long for the user group, but we should be runing the next one alongside the CLD Summit so I will try and schedule it towards the end of the day so CSLUG could join in.

Mike

0 Kudos
Message 7 of 8
(5,502 Views)

Nice possible solution. I had no idea HSL worked like that. I assumed (stupidly) that it was just another way to reference RGB.

I had a play around with the VI you posted using Vision Development and it works nicely. Some colours are still a bit difficult to read but generally it displays well.

Lucy, I've had a quick look around and came across an llb on the forums. Not sure if it will help. Have a look at page 1 message 5. http://forums.ni.com/t5/LabVIEW/Will-unicode-be-supported-by-LabVIEW/m-p/222956

Here are 2 other links that might help:

http://lavag.org/topic/12408-unicode-in-labview/

https://decibel.ni.com/content/docs/DOC-10153

Another option might be to look for a .net library to do the conversion. http://www.lingualizer.net/tools/files/category-localization-tools.html Just a thought.

Sounds like an interesting project you working on.

Greg

0 Kudos
Message 8 of 8
(5,502 Views)