----------------------------------------------------------------------* * Display a kernel in a pix * *----------------------------------------------------------------------*/ ! * \brief kernelDisplayInPix() * * \param[in] kel kernel * \param[in] size of grid interiors; odd; either 1 or a minimum size * of 17 is enforced
| 923 | * </pre> |
| 924 | */ |
| 925 | PIX * |
| 926 | kernelDisplayInPix(L_KERNEL *kel, |
| 927 | l_int32 size, |
| 928 | l_int32 gthick) |
| 929 | { |
| 930 | l_int32 i, j, w, h, sx, sy, cx, cy, width, x0, y0; |
| 931 | l_int32 normval; |
| 932 | l_float32 minval, maxval, max, val, norm; |
| 933 | PIX *pixd, *pixt0, *pixt1; |
| 934 | |
| 935 | PROCNAME("kernelDisplayInPix"); |
| 936 | |
| 937 | if (!kel) |
| 938 | return (PIX *)ERROR_PTR("kernel not defined", procName, NULL); |
| 939 | |
| 940 | /* Normalize the max value to be 255 for display */ |
| 941 | kernelGetParameters(kel, &sy, &sx, &cy, &cx); |
| 942 | kernelGetMinMax(kel, &minval, &maxval); |
| 943 | max = L_MAX(maxval, -minval); |
| 944 | if (max == 0.0) |
| 945 | return (PIX *)ERROR_PTR("kernel elements all 0.0", procName, NULL); |
| 946 | norm = 255. / (l_float32)max; |
| 947 | |
| 948 | /* Handle the 1 element/pixel case; typically with large kernels */ |
| 949 | if (size == 1 && gthick == 0) { |
| 950 | pixd = pixCreate(sx, sy, 8); |
| 951 | for (i = 0; i < sy; i++) { |
| 952 | for (j = 0; j < sx; j++) { |
| 953 | kernelGetElement(kel, i, j, &val); |
| 954 | normval = (l_int32)(norm * L_ABS(val)); |
| 955 | pixSetPixel(pixd, j, i, normval); |
| 956 | } |
| 957 | } |
| 958 | return pixd; |
| 959 | } |
| 960 | |
| 961 | /* Enforce the constraints for the grid line version */ |
| 962 | if (size < 17) { |
| 963 | L_WARNING("size < 17; setting to 17\n", procName); |
| 964 | size = 17; |
| 965 | } |
| 966 | if (size % 2 == 0) |
| 967 | size++; |
| 968 | if (gthick < 2) { |
| 969 | L_WARNING("grid thickness < 2; setting to 2\n", procName); |
| 970 | gthick = 2; |
| 971 | } |
| 972 | |
| 973 | w = size * sx + gthick * (sx + 1); |
| 974 | h = size * sy + gthick * (sy + 1); |
| 975 | pixd = pixCreate(w, h, 8); |
| 976 | |
| 977 | /* Generate grid lines */ |
| 978 | for (i = 0; i <= sy; i++) |
| 979 | pixRenderLine(pixd, 0, gthick / 2 + i * (size + gthick), |
| 980 | w - 1, gthick / 2 + i * (size + gthick), |
| 981 | gthick, L_SET_PIXELS); |
| 982 | for (j = 0; j <= sx; j++) |
nothing calls this directly
no test coverage detected