Search in sources :

Example 66 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class ConvolveImageStandard_SB method vertical.

public static void vertical(Kernel1D_S32 kernel, GrayU16 src, GrayI8 dst, int divisor, @Nullable GrowArray<DogArray_I32> workspaces) {
    workspaces = BoofMiscOps.checkDeclare(workspaces, DogArray_I32::new);
    // CONCURRENT_REMOVE_LINE
    final DogArray_I32 work = workspaces.grow();
    final short[] dataSrc = src.data;
    final byte[] dataDst = dst.data;
    final int[] dataKer = kernel.data;
    final int offset = kernel.getOffset();
    final int kernelWidth = kernel.getWidth();
    final int halfDivisor = divisor / 2;
    // WTF integer division is slower than converting to a float??
    final double divisionHack = 1.0 / divisor;
    final int imgWidth = dst.getWidth();
    final int imgHeight = dst.getHeight();
    final int yEnd = imgHeight - (kernelWidth - offset - 1);
    // CONCURRENT_BELOW BoofConcurrency.loopBlocks(offset, yEnd, workspaces, (work, y0, y1)->{
    final int y0 = offset, y1 = yEnd;
    int[] totalRow = BoofMiscOps.checkDeclare(work, imgWidth, true);
    for (int y = y0; y < y1; y++) {
        for (int k = 0; k < kernelWidth; k++) {
            final int kernelValue = dataKer[k];
            int indexSrc = src.startIndex + (y - offset + k) * src.stride;
            for (int i = 0; i < imgWidth; i++) {
                totalRow[i] += ((dataSrc[indexSrc++] & 0xFFFF) * kernelValue);
            }
        }
        int indexDst = dst.startIndex + y * dst.stride;
        for (int i = 0; i < imgWidth; i++) {
            dataDst[indexDst++] = (byte) ((totalRow[i] + halfDivisor) * divisionHack);
        }
        Arrays.fill(totalRow, 0, imgWidth, 0);
    }
// CONCURRENT_INLINE });
}
Also used : DogArray_I32(org.ddogleg.struct.DogArray_I32)

Example 67 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class ConvolveImageStandard_SB method vertical.

public static void vertical(Kernel1D_S32 kernel, GrayU16 src, GrayI16 dst, int divisor, @Nullable GrowArray<DogArray_I32> workspaces) {
    workspaces = BoofMiscOps.checkDeclare(workspaces, DogArray_I32::new);
    // CONCURRENT_REMOVE_LINE
    final DogArray_I32 work = workspaces.grow();
    final short[] dataSrc = src.data;
    final short[] dataDst = dst.data;
    final int[] dataKer = kernel.data;
    final int offset = kernel.getOffset();
    final int kernelWidth = kernel.getWidth();
    final int halfDivisor = divisor / 2;
    // WTF integer division is slower than converting to a float??
    final double divisionHack = 1.0 / divisor;
    final int imgWidth = dst.getWidth();
    final int imgHeight = dst.getHeight();
    final int yEnd = imgHeight - (kernelWidth - offset - 1);
    // CONCURRENT_BELOW BoofConcurrency.loopBlocks(offset, yEnd, workspaces, (work, y0, y1)->{
    final int y0 = offset, y1 = yEnd;
    int[] totalRow = BoofMiscOps.checkDeclare(work, imgWidth, true);
    for (int y = y0; y < y1; y++) {
        for (int k = 0; k < kernelWidth; k++) {
            final int kernelValue = dataKer[k];
            int indexSrc = src.startIndex + (y - offset + k) * src.stride;
            for (int i = 0; i < imgWidth; i++) {
                totalRow[i] += ((dataSrc[indexSrc++] & 0xFFFF) * kernelValue);
            }
        }
        int indexDst = dst.startIndex + y * dst.stride;
        for (int i = 0; i < imgWidth; i++) {
            dataDst[indexDst++] = (short) ((totalRow[i] + halfDivisor) * divisionHack);
        }
        Arrays.fill(totalRow, 0, imgWidth, 0);
    }
// CONCURRENT_INLINE });
}
Also used : DogArray_I32(org.ddogleg.struct.DogArray_I32)

Example 68 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class ConvolveImageStandard_SB method vertical.

public static void vertical(Kernel1D_S32 kernel, GrayU8 src, GrayI8 dst, int divisor, @Nullable GrowArray<DogArray_I32> workspaces) {
    workspaces = BoofMiscOps.checkDeclare(workspaces, DogArray_I32::new);
    // CONCURRENT_REMOVE_LINE
    final DogArray_I32 work = workspaces.grow();
    final byte[] dataSrc = src.data;
    final byte[] dataDst = dst.data;
    final int[] dataKer = kernel.data;
    final int offset = kernel.getOffset();
    final int kernelWidth = kernel.getWidth();
    final int halfDivisor = divisor / 2;
    // WTF integer division is slower than converting to a float??
    final double divisionHack = 1.0 / divisor;
    final int imgWidth = dst.getWidth();
    final int imgHeight = dst.getHeight();
    final int yEnd = imgHeight - (kernelWidth - offset - 1);
    // CONCURRENT_BELOW BoofConcurrency.loopBlocks(offset, yEnd, workspaces, (work, y0, y1)->{
    final int y0 = offset, y1 = yEnd;
    int[] totalRow = BoofMiscOps.checkDeclare(work, imgWidth, true);
    for (int y = y0; y < y1; y++) {
        for (int k = 0; k < kernelWidth; k++) {
            final int kernelValue = dataKer[k];
            int indexSrc = src.startIndex + (y - offset + k) * src.stride;
            for (int i = 0; i < imgWidth; i++) {
                totalRow[i] += ((dataSrc[indexSrc++] & 0xFF) * kernelValue);
            }
        }
        int indexDst = dst.startIndex + y * dst.stride;
        for (int i = 0; i < imgWidth; i++) {
            dataDst[indexDst++] = (byte) ((totalRow[i] + halfDivisor) * divisionHack);
        }
        Arrays.fill(totalRow, 0, imgWidth, 0);
    }
// CONCURRENT_INLINE });
}
Also used : DogArray_I32(org.ddogleg.struct.DogArray_I32)

Example 69 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class ConvolveImageStandard_SB method convolve.

public static void convolve(Kernel2D_S32 kernel, GrayU8 src, GrayI8 dest, int divisor, @Nullable GrowArray<DogArray_I32> workspaces) {
    workspaces = BoofMiscOps.checkDeclare(workspaces, DogArray_I32::new);
    // CONCURRENT_REMOVE_LINE
    final DogArray_I32 work = workspaces.grow();
    final int[] dataKernel = kernel.data;
    final byte[] dataSrc = src.data;
    final byte[] dataDst = dest.data;
    final int width = src.getWidth();
    final int height = src.getHeight();
    final int halfDivisor = divisor / 2;
    int offsetL = kernel.offset;
    int offsetR = kernel.width - kernel.offset - 1;
    // CONCURRENT_BELOW BoofConcurrency.loopBlocks(offsetL, height - offsetR,kernel.width, workspaces, (work,y0,y1) -> {
    final int y0 = offsetL, y1 = height - offsetR;
    int[] totalRow = BoofMiscOps.checkDeclare(work, src.width, false);
    for (int y = y0; y < y1; y++) {
        int indexSrcRow = src.startIndex + (y - offsetL) * src.stride - offsetL;
        for (int x = offsetL; x < width - offsetR; x++) {
            int indexSrc = indexSrcRow + x;
            int total = 0;
            for (int k = 0; k < kernel.width; k++) {
                total += (dataSrc[indexSrc++] & 0xFF) * dataKernel[k];
            }
            totalRow[x] = total;
        }
        // rest of the convolution rows are an addition
        for (int i = 1; i < kernel.width; i++) {
            indexSrcRow = src.startIndex + (y + i - offsetL) * src.stride - offsetL;
            int indexKer = i * kernel.width;
            for (int x = offsetL; x < width - offsetR; x++) {
                int indexSrc = indexSrcRow + x;
                int total = 0;
                for (int k = 0; k < kernel.width; k++) {
                    total += (dataSrc[indexSrc++] & 0xFF) * dataKernel[indexKer + k];
                }
                totalRow[x] += total;
            }
        }
        int indexDst = dest.startIndex + y * dest.stride + offsetL;
        for (int x = offsetL; x < width - offsetR; x++) {
            dataDst[indexDst++] = (byte) ((totalRow[x] + halfDivisor) / divisor);
        }
    }
// CONCURRENT_INLINE });
}
Also used : DogArray_I32(org.ddogleg.struct.DogArray_I32)

Example 70 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class ImplMedianSortNaive method process.

/**
 * Performs a median filter.
 *
 * @param input Raw input image.
 * @param output Filtered image.
 * @param radiusX Size of the filter region. x-axis
 * @param radiusY Size of the filter region. Y-axis
 * @param workArrays (Optional) Storage for internal workspace. Nullable.
 */
public static void process(GrayI input, GrayI output, int radiusX, int radiusY, @Nullable GrowArray<DogArray_I32> workArrays) {
    final int w = 2 * radiusX + 1;
    final int h = 2 * radiusY + 1;
    workArrays = BoofMiscOps.checkDeclare(workArrays, DogArray_I32::new);
    // CONCURRENT_REMOVE_BELOW
    DogArray_I32 workspace = workArrays.grow();
    // CONCURRENT_BELOW BoofConcurrency.loopBlocks(0, input.height, h, workArrays, (workspace,y0,y1)->{
    final int y0 = 0, y1 = input.height;
    int[] workArray = BoofMiscOps.checkDeclare(workspace, w * h, false);
    for (int y = y0; y < y1; y++) {
        int minI = y - radiusY;
        int maxI = y + radiusY + 1;
        // bound the y-axis inside the image
        if (minI < 0)
            minI = 0;
        if (maxI > input.height)
            maxI = input.height;
        for (int x = 0; x < input.width; x++) {
            int minJ = x - radiusX;
            int maxJ = x + radiusX + 1;
            // bound the x-axis to be inside the image
            if (minJ < 0)
                minJ = 0;
            if (maxJ > input.width)
                maxJ = input.width;
            int index = 0;
            for (int i = minI; i < maxI; i++) {
                for (int j = minJ; j < maxJ; j++) {
                    workArray[index++] = input.unsafe_get(j, i);
                }
            }
            // use quick select to avoid sorting the whole list
            int median = QuickSelect.select(workArray, index / 2, index);
            output.set(x, y, median);
        }
    }
// CONCURRENT_ABOVE }});
}
Also used : DogArray_I32(org.ddogleg.struct.DogArray_I32)

Aggregations

DogArray_I32 (org.ddogleg.struct.DogArray_I32)192 Test (org.junit.jupiter.api.Test)73 Point2D_I32 (georegression.struct.point.Point2D_I32)24 ArrayList (java.util.ArrayList)21 Point2D_F64 (georegression.struct.point.Point2D_F64)17 DogArray (org.ddogleg.struct.DogArray)17 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)15 GrayS32 (boofcv.struct.image.GrayS32)10 VerbosePrint (org.ddogleg.struct.VerbosePrint)7 View (boofcv.alg.structure.PairwiseImageGraph.View)6 AssociatedIndex (boofcv.struct.feature.AssociatedIndex)6 GrayI (boofcv.struct.image.GrayI)5 Point3D_F64 (georegression.struct.point.Point3D_F64)5 GrowArray (pabeles.concurrency.GrowArray)5 DetectDescribePoint (boofcv.abst.feature.detdesc.DetectDescribePoint)4 BTrack (boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BTrack)4 AssociatedTripleIndex (boofcv.struct.feature.AssociatedTripleIndex)4 SceneObservations (boofcv.abst.geo.bundle.SceneObservations)3 SceneWorkingGraph (boofcv.alg.structure.SceneWorkingGraph)3 ConfigAssociateGreedy (boofcv.factory.feature.associate.ConfigAssociateGreedy)3