Package ptolemy.data

Examples of ptolemy.data.DoubleMatrixToken


     @exception IllegalActionException If a contained method throws it.
     */
    public void fire() throws IllegalActionException {
        super.fire();

        DoubleMatrixToken doubleMatrixToken = (DoubleMatrixToken) input.get(0);
        double[][] data = doubleMatrixToken.doubleMatrix();
        int width = doubleMatrixToken.getRowCount();
        int height = doubleMatrixToken.getColumnCount();
        double[][] outputData = new double[width][height];
        int windowSize = 3;

        // Iterate over each pixel.
        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                while (true) {
                    int dist = (windowSize - 1) / 2;

                    // Check if we can create a region of interest or
                    // not.  If we can't (i.e. we are at or near the
                    // edge of an image) then just keep the data.
                    if (((i - dist) < 0) || ((j - dist) < 0)
                            || ((i + dist) >= width) || ((j + dist) >= height)) {
                        outputData[i][j] = data[i][j];
                        windowSize = 3;
                        break;
                    } else {
                        double[][] temp = new double[windowSize][windowSize];

                        // Create a local region of interest around the pixel.
                        for (int k = (i - dist); k <= (i + dist); k++) {
                            for (int l = (j - dist); l <= (j + dist); l++) {
                                temp[k - (i - dist)][l - (j - dist)] = data[k][l];
                            }
                        }

                        double median = _getMedian(temp, windowSize);
                        double max = _getMaximum(temp, windowSize);
                        double min = _getMinimum(temp, windowSize);

                        // If the median of the region of interest is
                        // strictly less than the maximum value, and
                        // strictly greater than the minimum value, we
                        // then have two routes.  If the data in the
                        // center is strictly greater than the
                        // minimum, and strictly less than the maximum,
                        // then just keep the data point.  If it is
                        // either the minimum or the maximum, then
                        // output the medium because there is a very
                        // good chance that the pixel was noised.
                        // After this, the window size is reset.
                        if ((median > min) && (median < max)) {
                            if ((data[i][j] > min) && (data[i][j] < max)) {
                                outputData[i][j] = data[i][j];
                                windowSize = 3;
                                break;
                            } else {
                                outputData[i][j] = median;
                                windowSize = 3;
                                break;
                            }
                        } else if (windowSize < _maxWindowSize) {
                            // If this statement is reached, this
                            // means that the median was equal to
                            // either the minimum or the maximum (or
                            // quite possibly both if the region of
                            // interest had constant intensity.
                            // Increase the window size, if it is less
                            // than the maximum window size.
                            windowSize = windowSize + 2;
                        } else {
                            // If this statement is reached, we've
                            // already hit the maximum window size, in
                            // which case, just output the data and
                            // reset the window size.
                            outputData[i][j] = data[i][j];
                            windowSize = 3;
                            break;
                        }
                    }
                }
            }
        }

        output.send(0, new DoubleMatrixToken(outputData));
    }
View Full Code Here


     */
    public JAIBandCombine(CompositeEntity container, String name)
            throws IllegalActionException, NameDuplicationException {
        super(container, name);

        matrix = new Parameter(this, "matrix", new DoubleMatrixToken(
                _initialMatrix));
    }
View Full Code Here

     *   or if a token is received that contains a null image.
     */
    public void fire() throws IllegalActionException {
        super.fire();

        DoubleMatrixToken doubleMatrixToken = (DoubleMatrixToken) input.get(0);
        double[][] data = doubleMatrixToken.doubleMatrix();
        int width = doubleMatrixToken.getRowCount();
        int height = doubleMatrixToken.getColumnCount();
        double[] newData = new double[width * height];
        _maxValue = 1;
        _minValue = 0;

        if (_scale) {
View Full Code Here

        secondMask = new StringAttribute(this, "secondMask");
        secondMask.setExpression("Sobel Vertical");
        _secondMask = _SOBEL_VERTICAL;

        userSpecifiedFirstMask = new Parameter(this, "userSpecifiedFirstMask",
                new DoubleMatrixToken(_initialMatrix));
        userSpecifiedSecondMask = new Parameter(this,
                "userSpecifiedSecondMask",
                new DoubleMatrixToken(_initialMatrix));
    }
View Full Code Here

            throws IllegalActionException, NameDuplicationException {
        super(container, name);
        input.setTypeEquals(BaseType.OBJECT);
        output.setTypeEquals(BaseType.OBJECT);

        filter = new Parameter(this, "filter", new DoubleMatrixToken(
                _initialMatrix));
    }
View Full Code Here

     @exception IllegalActionException If a contained method throws it.
     */
    public void attributeChanged(Attribute attribute)
            throws IllegalActionException {
        if (attribute == filter) {
            DoubleMatrixToken matrix = (DoubleMatrixToken) filter.getToken();
            double[][] matrixValue = matrix.doubleMatrix();
            int height = matrix.getRowCount();
            int width = matrix.getColumnCount();
            float[] floatArray = new float[width * height];
            int count = 0;

            for (int i = 0; i < height; i = i + 1) {
                for (int j = 0; j < width; j = j + 1) {
View Full Code Here

                }
            }
        }

        //DoubleMatrixToken matrixToken = new DoubleMatrixToken(data);
        output.send(0, new DoubleMatrixToken(data));
    }
View Full Code Here

            for (int j = 0; j < _columns; j++) {
                result[i][j] = ((DoubleToken) row[j]).doubleValue();
            }
        }

        output.send(0, new DoubleMatrixToken(result, MatrixToken.DO_NOT_COPY));
    }
View Full Code Here

     */
    public void attributeChanged(Attribute attribute)
            throws IllegalActionException {
        if (attribute == initialStates) {
            // The initialStates parameter should be a row vector.
            DoubleMatrixToken token = (DoubleMatrixToken) initialStates
                    .getToken();

            if (token == null) {
                return;
            }

            if ((token.getRowCount() != 1) || (token.getColumnCount() < 1)) {
                throw new IllegalActionException(this,
                        "The initialStates must be a row vector.");
            }

            // Changes of the initialStates parameter are ignored after
View Full Code Here

            for (int i = 0; i < size; i++) {
                data[0][i] = ((DoubleToken) input.get(i)).doubleValue();
            }
        }

        DoubleMatrixToken result = new DoubleMatrixToken(data);

        output.send(0, result);
    }
View Full Code Here

TOP

Related Classes of ptolemy.data.DoubleMatrixToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.