"Color" (Comparison Method)
Details
- The "Color" comparison method considers two colors to be equivalent if they do not differ beyond a given tolerance.
- This tolerance is set using the Tolerance option in AssessmentFunction.
- By default, the distance between each value of the answer key and the submitted answer is computed using ColorDistance. The DistanceFunction option can be used to specify any of the settings supported by ColorDistance.
- When multiple values in the answer key are within the tolerance range of an answer, the closest value is selected.
Examples
open all close allBasic Examples (2)
Create an AssessmentFunction for a color question:
lightblue = AssessmentFunction[{LightBlue}, "Color", Tolerance -> 0.3]lightblue[Blue]lightblue[Lighter[Blue, .8]]Create a color assessment with multiple correct answers. Note that the "Color" comparison method is automatically chosen:
redwhiteblue = AssessmentFunction[{Red -> 1, White -> 2, Blue -> 3}, Tolerance -> 0.2]Specify an answer using RGBColor:
answer = RGBColor[0, 0.1, 0.9]result = redwhiteblue[answer]result["Score"]Scope (2)
Create an assessment with a default tolerance of zero:
black = AssessmentFunction[Black, "Color"]The answer must be exactly the same to be considered correct:
black[GrayLevel[0.0001]]black[GrayLevel[0.]]Any valid color directive can be used in the answer keys or submitted answer:
rgbtest = AssessmentFunction[RGBColor[1, 0, 1], Tolerance -> 0.2]rgbtest /@ {CMYKColor[0., 1., 0., 0.], LABColor[0.60, 0.939, -0.60], XYZColor[0.57, 0.28, 0.72], LCHColor[0.60, 1.11, 0.90], Hue[0.83, 1., 1.], LUVColor[0.60, 0.94, -0.97]}Options (1)
DistanceFunction (1)
Set the DistanceFunction to compare based on luminance:
answerkeycolor = LABColor[0.52, -0.05, -0.18]luminancecompare = AssessmentFunction[answerkeycolor, Tolerance -> 0.2, DistanceFunction -> "DeltaL"]Colors with similar luminance are marked as correct:
luminancecompare[LABColor[0.58, .2, .6]]luminancecompare[RGBColor[0.91, 0.3, 0.01]]luminancecompare[RGBColor[0.39, 0.11, 0.01]]Applications (3)
Create a QuestionObject for color selection:
QuestionObject[QuestionInterface["SelectColor", <|"Prompt" -> "What color is a pickle?"|>], AssessmentFunction[Green, Tolerance -> 0.2]]With[{p = RandomEntity["Pokemon"]}, QuestionObject[QuestionInterface["SelectColor", <|"Prompt" -> Column[{"What color is this pokemon? ", ColorConvert[p["Image"], "Grayscale"]}]|>], AssessmentFunction[DominantColors[p["Image"]], Tolerance -> 0.3]]]Create a QuestionObject for assessing the selection of a color from an image:
With[{mandrill = Image[ExampleData[{"TestImage", "Mandrill"}], ImageSize -> Medium]}, QuestionObject[QuestionInterface["ClickLocations", <|"Prompt" -> "Choose a red location in the image", "Background" -> mandrill|>], AssessmentFunction[Red, <|"ComparisonMethod" -> "Color"|>, Tolerance -> 0.4][RGBColor[First@PixelValue[mandrill, #]]]&]
]See Also
AssessmentFunction QuestionObject ColorDistance ColorConvert
Question Interface Types: SelectColor ClickLocations
Comparison Methods: Vector