@@ -764,29 +764,49 @@ def _score100(component: float) -> int:
764764def _quality_advice (
765765 * ,
766766 brightness_mean : float ,
767+ brightness_component : float ,
767768 contrast_component : float ,
768769 sharpness_component : float ,
769770 noise_component : float ,
770771) -> List [str ]:
771772 advice : List [str ] = []
772773
773- if brightness_mean < QUALITY_BRIGHTNESS_USABLE_MIN :
774- advice .append ("The photo is too dark. Retake it in brighter light." )
775- elif brightness_mean < QUALITY_BRIGHTNESS_IDEAL_MIN :
776- advice .append ("The photo is a little dark. Add more light if possible." )
777- elif brightness_mean > QUALITY_BRIGHTNESS_USABLE_MAX :
778- advice .append ("The photo is overexposed. Reduce glare or strong direct light." )
779- elif brightness_mean > QUALITY_BRIGHTNESS_IDEAL_MAX :
780- advice .append ("The photo is a little bright. Try reducing glare." )
774+ brightness_score = _score100 (brightness_component )
775+ contrast_score = _score100 (contrast_component )
776+ sharpness_score = _score100 (sharpness_component )
777+ noise_score = _score100 (noise_component )
781778
782- if contrast_component < 0.5 :
783- advice .append ("The parts do not stand out clearly. Use a plain background and avoid shadows." )
779+ is_dark = brightness_mean < QUALITY_BRIGHTNESS_IDEAL_MIN
780+ brightness_fail = (
781+ "The photo is too dark for reliable checking. Please retake it in brighter light."
782+ if is_dark
783+ else "The photo is overexposed for reliable checking. Please retake it with less glare or strong direct light."
784+ )
785+ brightness_warn = (
786+ "The photo is a little dark. Add more light next time if possible."
787+ if is_dark
788+ else "The photo is a little bright. Try reducing glare next time."
789+ )
790+
791+ if brightness_score <= QUALITY_MIN_COMPONENT_SCORE :
792+ advice .append (brightness_fail )
793+ elif brightness_score <= 50 :
794+ advice .append (brightness_warn )
795+
796+ if contrast_score <= QUALITY_MIN_COMPONENT_SCORE :
797+ advice .append ("The parts do not stand out clearly enough for reliable checking. Please retake the photo with a plain background and fewer shadows." )
798+ elif contrast_score <= 50 :
799+ advice .append ("The parts do not stand out very clearly. Use a plain background and avoid shadows next time." )
784800
785- if sharpness_component < 0.5 :
786- advice .append ("The photo is blurry. Hold the camera still and refocus before taking the photo." )
801+ if sharpness_score <= QUALITY_MIN_COMPONENT_SCORE :
802+ advice .append ("The photo is too blurry for reliable checking. Please retake it after holding the camera still and refocusing." )
803+ elif sharpness_score <= 50 :
804+ advice .append ("The photo is a little blurry. For better results, hold the camera still and refocus next time." )
787805
788- if noise_component < 0.5 :
789- advice .append ("The photo looks noisy or grainy. Use better lighting and avoid digital zoom." )
806+ if noise_score <= QUALITY_MIN_COMPONENT_SCORE :
807+ advice .append ("The photo is too noisy or grainy for reliable checking. Please retake it with better lighting and avoid digital zoom." )
808+ elif noise_score <= 50 :
809+ advice .append ("The photo looks a little noisy or grainy. Use better lighting and avoid digital zoom next time." )
790810
791811 if not advice :
792812 advice .append ("The photo is clear enough for the next check." )
@@ -849,6 +869,7 @@ def compute_image_quality_metrics(img_bgr: np.ndarray) -> Dict[str, Any]:
849869 )
850870 advice = _quality_advice (
851871 brightness_mean = brightness_mean ,
872+ brightness_component = brightness_component ,
852873 contrast_component = contrast_component ,
853874 sharpness_component = sharpness_component ,
854875 noise_component = noise_component ,
0 commit comments