444 int histJND = maxCount/50;
448 int tmpValleyArray[256];
449 for(i=0; i<256; i++) { tmpValleyArray[i] = 0; }
455 int firstMinIndex = 0;
456 int lastMinIndex = 0;
459 bool slopeNeg =
false;
461 for(i = 1; i<256; i++ )
476 tmpValleyArray[ (firstMinIndex + lastMinIndex)/2 ] = 1;
495 if(tmpValleyArray[i] == 1 ) numValleys++;
500 if(tmpValleyArray[0] != 1)
502 if(tmpValleyArray[255] != 1)
516 if( tmpValleyArray[i] == 1)
542 for(i=
MAX(0, maxIndex-lumJND); i<
MIN(256, maxIndex+lumJND); i++)
628 float outS, outM, outL;
637 S1 =
MAX( 1.0f - ((
clusters[cluster].meanMode/JND) / 1.5f), 0 );
639 if( (
clusters[cluster].meanMode/JND) <= 1.5f )
640 M1 =
MAX( (
clusters[cluster].meanMode/JND) - 0.5f, 0 );
642 M1 =
MAX( 2.5f - (
clusters[cluster].meanMode/JND), 0 );
644 L1 =
MAX( ((
clusters[cluster].meanMode/JND) - 1.5f) / 1.5f, 0 );
646 S2 =
MAX( 1.0f - (
clusters[cluster].mode/JND), 0 );
648 if( (
clusters[cluster].mode/JND) <= 1.0f )
649 M2 =
MAX( -1.0f + 2*(
clusters[cluster].mode/JND), 0 );
651 M2 =
MAX( 3.0f - 2*(
clusters[cluster].mode/JND), 0 );
655 S3 =
MAX( 1.0f - 2*
clusters[cluster].pixelCount, 0 );
656 L3 =
MAX( -1.0f + 2*
clusters[cluster].pixelCount, 0 );
716 float A = outM + 0.5f;
717 float B = 2.5f - outM;
718 float C = 1.5f * (outL + 1);
719 float D = 1.5f * (outM + 1);
720 float E = 2.5f - outL;
724 if( outM > 0.5f && outL > 0.5f )
727 float area1 = ((A-0.5f)*outM)/2;
728 float area2 = outM * (
B-A);
729 float area3 = ((2.1f-
B) * (outM - 0.5)) / 2;
730 float area4 = (2.1 -
B) * 0.5f;
731 float area5 = ((C - 2.1f) * (outL - 0.5)) / 2;
732 float area6 = (C - 2.1f) * 0.5f;
733 float area7 = (3.0f - C) * outL;
736 float halfArea = (area1 + area2 + area3 + area4 + area5 + area6 + area7) / 2;
741 if( area1 > halfArea )
743 clusters[cluster].
beta = 0.5f + (float)sqrt(2*halfArea);
746 else if( area1 + area2 > halfArea )
748 clusters[cluster].
beta = ((halfArea - area1) / outM) + A;
751 else if( area1 + area2 + area3 + area4 > halfArea )
755 float c = area1 + area2 + area3 - halfArea -
B/2 - 2.625f;
759 else if( area1 + area2 + area3 + area4 + area5 + area6 > halfArea )
763 float c = area1 + area2 + area3 + area4 - halfArea;
769 clusters[cluster].
beta = ((halfArea - (area1 + area2 + area3 + area4 + area5 + area6) ) / outL) + C;
774 else if ( outM < 0.5f && outL > outM )
777 float area1 = (outM*(A-0.5f)) / 2;
778 float area2 = (D-A) * outM;
779 float area3 = ((C-D) * (outL - outM)) / 2;
780 float area4 = (C-D) * outM;
781 float area5 = (3.0f - C) * outL;
784 float halfArea = (area1 + area2 + area3 + area4 + area5) / 2;
789 if( area1 > halfArea )
791 clusters[cluster].
beta = 0.5f + (float)sqrt(2*halfArea);
794 else if( area1 + area2 > halfArea )
796 clusters[cluster].
beta = ((halfArea - area1) / outM) + A;
799 else if( area1 + area2 + area3 + area4 > halfArea )
802 float b = outM - 0.5f - D/3;
803 float c = area1 + area2 - D*outM + D/2 - halfArea;
809 clusters[cluster].
beta = ((halfArea - (area1 + area2 + area3 + area4) ) / outL) + C;
817 float area1 = (outM*(A-0.5f)) / 2;
818 float area2 = (
B-A) * outM;
819 float area3 = ((E-
B) * (outM - outL)) / 2;
820 float area4 = (E-
B) * outL;
821 float area5 = (3.0f - E) * outL;
824 float halfArea = (area1 + area2 + area3 + area4 + area5) / 2;
829 if( area1 > halfArea )
831 clusters[cluster].
beta = 0.5f + (float)sqrt(2*halfArea);
834 else if( area1 + area2 > halfArea )
836 clusters[cluster].
beta = ((halfArea - area1) / outM) + A;
839 else if( area1 + area2 + area3 + area4 > halfArea )
842 float b = E/2 + 2.5f/2;
843 float c = area3 - 2.5f*E/2;
849 clusters[cluster].
beta = ((halfArea - (area1 + area2 + area3 + area4) ) / outL) + E;
868 for( y=0; y<
image->height(); y++)
870 scanLine =
image->scanLine(y);
871 for( x=0; x<
image->width(); x++)
874 rgb = ((QRgb*)scanLine+x);
875 *rgb = qRgb( 0, 0, 0 );
881 if( ESF == 0.0f )
continue;
885 float edgeMagThresh = -1.0f;
889 if(lum >=
clusters[cluster].minLuminance &&
890 lum <=
clusters[cluster].maxLuminance)
909 int neighborIndex1 = -1;
910 int neighborIndex2 = -1;
915 neighborIndex1 = x-1 + y*
image->width();
916 if( x < image->
width() - 1 )
917 neighborIndex2 = x+1 + y*
image->width();
919 else if(direction == 1)
921 if( x > 0 && y < image->
height() - 1 )
922 neighborIndex1 = x-1 + (y+1)*
image->width();
923 if( x < image->
width() - 1 && y > 0 )
924 neighborIndex2 = x+1 + (y-1)*
image->width();
926 else if(direction == 2)
928 if( y < image->
height() - 1 )
929 neighborIndex1 = x + (y+1)*
image->width();
931 neighborIndex2 = x + (y-1)*
image->width();
933 else if(direction == 3)
935 if( x < image->
width() - 1 && y < image->
height() - 1 )
936 neighborIndex1 = x+1 + (y+1)*
image->width();
938 neighborIndex2 = x-1 + (y-1)*
image->width();
942 if( neighborIndex1 != -1 &&
948 if( neighborIndex2 != -1 &&
954 *rgb = qRgb( 255, 255, 255 );