Search in sources :

Example 1 with ProgressMonitorThread

use of boofcv.io.ProgressMonitorThread in project BoofCV by lessthanoptimal.

the class ShowImageBlurApp method performUpdate.

private synchronized void performUpdate() {
    if (input == null || output == null)
        return;
    String message = active == 2 ? "Median is slow" : "";
    progress = 0;
    ProgressMonitorThread monitor = new MyMonitor(this, message);
    monitor.start();
    for (int i = 0; i < input.getNumBands(); i++, progress++) {
        T bandIn = input.getBand(i);
        T bandOut = output.getBand(i);
        T bandStorage = storage.getBand(i);
        switch(active) {
            case 0:
                GBlurImageOps.gaussian(bandIn, bandOut, -1, radius, bandStorage);
                break;
            case 1:
                GBlurImageOps.mean(bandIn, bandOut, radius, bandStorage);
                break;
            case 2:
                GBlurImageOps.median(bandIn, bandOut, radius);
                break;
        }
    }
    monitor.stopThread();
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            ConvertBufferedImage.convertTo(output, renderedImage, true);
            gui.repaint();
        }
    });
}
Also used : ProgressMonitorThread(boofcv.io.ProgressMonitorThread)

Example 2 with ProgressMonitorThread

use of boofcv.io.ProgressMonitorThread in project BoofCV by lessthanoptimal.

the class ShowImageBlurApp method processImage.

@Override
public void processImage(int sourceID, long frameID, final BufferedImage buffered, ImageBase input) {
    Planar<T> image = (Planar<T>) input;
    // median can take a while. Disable the GUI
    if (inputMethod == InputMethod.IMAGE) {
        SwingUtilities.invokeLater(() -> {
            controls.comboAlg.setEnabled(false);
            controls.spinnerRadius.setEnabled(false);
        });
    }
    // Let the user know something is happening
    ProgressMonitorThread monitor = new MyMonitor(this, "Please Wait");
    monitor.start();
    long time0 = System.nanoTime();
    switch(active) {
        case 0:
            GBlurImageOps.gaussian(image, output, -1, radius, storage);
            break;
        case 1:
            GBlurImageOps.mean(image, output, radius, storage, workspaces);
            break;
        case 2:
            GBlurImageOps.median(image, output, radius, radius, workspaces);
            break;
    }
    long time1 = System.nanoTime();
    monitor.stopThread();
    ConvertBufferedImage.convertTo(output, renderedImage, true);
    SwingUtilities.invokeLater(() -> {
        if (inputMethod == InputMethod.IMAGE) {
            controls.comboAlg.setEnabled(true);
            controls.spinnerRadius.setEnabled(true);
        }
        controls.setTime((time1 - time0) * 1e-6);
        gui.setImageRepaint(renderedImage);
    });
}
Also used : ProgressMonitorThread(boofcv.io.ProgressMonitorThread)

Example 3 with ProgressMonitorThread

use of boofcv.io.ProgressMonitorThread in project BoofCV by lessthanoptimal.

the class ShowColorModelApp method performUpdate.

private synchronized void performUpdate() {
    if (input == null || output == null)
        return;
    progress = 0;
    ProgressMonitorThread monitor = new MyMonitor(this, "");
    monitor.start();
    final String[] names = new String[3];
    final BufferedImage[] out = new BufferedImage[3];
    for (int i = 0; i < 3; i++) {
        out[i] = new BufferedImage(input.width, input.height, BufferedImage.TYPE_INT_RGB);
    }
    switch(active) {
        case 0:
            names[0] = "Red";
            names[1] = "Green";
            names[2] = "Blue";
            output.setTo(input);
            ConvertBufferedImage.convertTo(output.getBand(0), out[0]);
            ConvertBufferedImage.convertTo(output.getBand(1), out[1]);
            ConvertBufferedImage.convertTo(output.getBand(2), out[2]);
            break;
        case 1:
            names[0] = "Hue";
            names[1] = "Saturation";
            names[2] = "Value";
            ColorHsv.rgbToHsv(input, output);
            setNaN(output.getBand(0));
            PixelMath.multiply(output.getBand(0), (float) (255.0 / (2 * Math.PI)), output.getBand(0));
            PixelMath.multiply(output.getBand(1), 255.0f, output.getBand(1));
            ConvertBufferedImage.convertTo(output.getBand(0), out[0]);
            ConvertBufferedImage.convertTo(output.getBand(1), out[1]);
            ConvertBufferedImage.convertTo(output.getBand(2), out[2]);
            break;
        case 2:
            names[0] = "Y";
            names[1] = "U";
            names[2] = "V";
            ColorYuv.rgbToYuv(input, output);
            ConvertBufferedImage.convertTo(output.getBand(0), out[0]);
            VisualizeImageData.colorizeSign(output.getBand(1), out[1], -1);
            VisualizeImageData.colorizeSign(output.getBand(2), out[2], -1);
            break;
        case 3:
            names[0] = "X";
            names[1] = "Y";
            names[2] = "Z";
            ColorXyz.rgbToXyz(input, output);
            PixelMath.multiply(output.getBand(1), 255, output.getBand(1));
            VisualizeImageData.colorizeSign(output.getBand(0), out[0], -1);
            ConvertBufferedImage.convertTo(output.getBand(1), out[1]);
            VisualizeImageData.colorizeSign(output.getBand(2), out[2], -1);
            break;
        case 4:
            names[0] = "L";
            names[1] = "A";
            names[2] = "B";
            ColorLab.rgbToLab(input, output);
            VisualizeImageData.grayMagnitude(output.getBand(0), out[0], -1);
            VisualizeImageData.colorizeSign(output.getBand(1), out[1], -1);
            VisualizeImageData.colorizeSign(output.getBand(2), out[2], -1);
            break;
    }
    monitor.stopThread();
    SwingUtilities.invokeLater(() -> {
        gui.reset();
        for (int i = 0; i < 3; i++) {
            gui.addImage(out[i], names[i]);
        }
        gui.setPreferredSize(new Dimension(input.width, input.height));
        gui.repaint();
        processedImage = true;
    });
}
Also used : ProgressMonitorThread(boofcv.io.ProgressMonitorThread) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Aggregations

ProgressMonitorThread (boofcv.io.ProgressMonitorThread)3 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 BufferedImage (java.awt.image.BufferedImage)1