MCPcopy Create free account
hub / github.com/DentonW/DevIL / ILAPIENTRY iluEqualize2

Function ILAPIENTRY iluEqualize2

DevIL/src-ILU/src/ilu_manip.cpp:913–1023  ·  view source on GitHub ↗

Method from the paper "Underwater image quality enhancement through composition of dual - intensity images and Rayleigh - stretching" by Ghani and Isa (http://springerplus.springeropen.com/articles/10.1186/2193-1801-3-757), DOI : 10.1186 / 2193 - 1801 - 3 - 757 Note that the ordering of the colors does not matter for the first part of this method.

Source from the content-addressed store, hash-verified

911// DOI : 10.1186 / 2193 - 1801 - 3 - 757
912// Note that the ordering of the colors does not matter for the first part of this method.
913ILboolean ILAPIENTRY iluEqualize2(void)
914{
915 iluCurImage = ilGetCurImage();
916 if (iluCurImage == NULL) {
917 ilSetError(ILU_ILLEGAL_OPERATION);
918 return 0;
919 }
920
921 // @TODO: Change to work with other types!
922 if (iluCurImage->Bpc > 1 || (iluCurImage->Format != IL_RGB && iluCurImage->Format != IL_RGBA
923 && iluCurImage->Format != IL_BGR && iluCurImage->Format != IL_BGRA)) {
924 ilSetError(ILU_INTERNAL_ERROR);
925 return IL_FALSE;
926 }
927
928 // Start of the Modified Von Kries hypothesis
929
930 ILdouble ChanAvgs[3] = { 0.0, 0.0, 0.0 };
931 ILuint NumPix = iluCurImage->Width * iluCurImage->Height;
932 if (NumPix < 1) {
933 ilSetError(IL_INTERNAL_ERROR);
934 return IL_FALSE;
935 }
936 for (ILuint i = 0; i < iluCurImage->SizeOfData; i += iluCurImage->Bpp)
937 {
938 ChanAvgs[0] += iluCurImage->Data[i + 0];
939 ChanAvgs[1] += iluCurImage->Data[i + 1];
940 ChanAvgs[2] += iluCurImage->Data[i + 2];
941 }
942 ChanAvgs[0] /= NumPix;
943 ChanAvgs[1] /= NumPix;
944 ChanAvgs[2] /= NumPix;
945
946 //@TODO: This is a really crude way of sorting the array - could be much simpler code
947 // in C++ or using an actual sorting function. With only 3 elements, this isn't too bad.
948 ILdouble ChanAvgsCopy[3];
949 ChanAvgsCopy[0] = IL_MIN(ChanAvgs[0], IL_MIN(ChanAvgs[1], ChanAvgs[2]));
950 ChanAvgsCopy[2] = IL_MAX(ChanAvgs[0], IL_MAX(ChanAvgs[1], ChanAvgs[2]));
951 ChanAvgsCopy[1] = -1; // Just a dummy value
952
953 ILuint MinPos = -1, MaxPos = -1;
954 for (ILuint i = 0; i < 3; i++)
955 {
956 if (ChanAvgs[i] == ChanAvgsCopy[0])
957 MinPos = i;
958 if (ChanAvgs[i] == ChanAvgsCopy[2])
959 MaxPos = i;
960 }
961 for (ILuint i = 0; i < 3; i++)
962 {
963 if (i != MinPos && i != MaxPos)
964 ChanAvgsCopy[1] = ChanAvgs[i];
965 }
966
967 if (ChanAvgsCopy[0] < 1.0 || ChanAvgsCopy[2] < 1.0) {
968 // This prevents division by 0 - could possibly be lowered less than 1
969 //ilSetError(IL_INTERNAL_ERROR);
970 return IL_FALSE;

Callers

nothing calls this directly

Calls 1

ilSetErrorFunction · 0.85

Tested by

no test coverage detected