Notifications
Clear all

[Closed] comparing values within threshold

hi,
I have 2 int variables, and 1 threshold value.

I want to compare the two values, and check if they are within the threshold.

Example:

val1 = 10
 val2 = 15
 Threshold = 6
 --Values are within threshold
 return true
 
val1 = 15
  val2 = 10
  Threshold = 3
 --Values are not within threshold
  return false

the reason for this is that I’m checking similar colors against each other, and I’ve got everything to work fine, except this last part.
I need the comparing line this because many colors are “close enough” for me to use them together.

7 Replies

May be something like this:

(
	function IsInThreshold val1 val2 tresh =
	(
		if (abs (val1-val2)) < tresh then
		(
			print "In threshold"
			return true
		)
		else
		(
			print "not in threshold"
			return false
		)
	)
	
	IsInThreshold 15 13 3
)
 PEN

How about just using the closeEnough function.

the easiest and fastest way to compare two integers with threshold is as miauu showed:
abs (v1-v2)
against [b]threshold

[/b]but looking at your question I’m not sure you are going to calculate the color distance the right way? Just curious, how do you see the color comparison function?

I’m writing a tool that checks each RGB of the diffuse color specified in the material.
This is because we have many models with (for instance) yellow color, but each might vary a bit,
this is why I need the threshold.

I then scan through the scene, and I instance all “almost same yellow” to the first yellow material.

This enables us to change shaders more quickly in the future, and helps us clean up our scenes.

I’m implementing the code now – I’ll post when done.
thanks to all of you who replied.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

that’s what i saw… the method that you use is not correct. usually for the color distance people use distance between RGB vectors in Cartesian coordinates.
distance (color1 as point3) (color2 as point3) in case of MXS
It’s much more accurate. but for colors (how people see them) there are some other algorithms. the better results you can get in LAB or LCH color system. (try google for Color difference)

It works perfectly miauu, thanks for the help!

Maybe worth to test [b]CompareBitmaps/b function as well.