Package ptolemy.data

Examples of ptolemy.data.IntMatrixToken


        super.fire();
        int i;
        int j;
        int y;
        int partitionNumber;
        IntMatrixToken message;

        message = (IntMatrixToken) input.get(0);

        if ((message.getRowCount() != _imageRows)
                || (message.getColumnCount() != _imageColumns)) {
            throw new IllegalActionException("Input data must be imageRows "
                    + "by imageColumns");
        }

        int[][] image = message.intMatrix();

        for (j = 0, partitionNumber = 0; j < _imageRows; j += _partitionRows) {
            for (i = 0; i < _imageColumns; i += _partitionColumns, partitionNumber++) {
                for (y = 0; y < _partitionRows; y++) {
                    System.arraycopy(image[j + y], i, _part[y], 0,
                            _partitionColumns);
                }

                _partitions[partitionNumber] = new IntMatrixToken(_part);
            }
        }

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


        int i;
        int j;
        int[][] frame;
        int frameElement;

        IntMatrixToken message = (IntMatrixToken) input.get(0);
        frame = message.intMatrix();

        // Construct a color distribution histogram for the input image:
        // Assuming the color bound for the input 0 and 255. If color detected
        // that has color either bigger than 255 OR small than 0, then throw an
        // illegal action exception.
        for (i = 0; i < 256; i++) {
            colorHistogram[i] = 0;
        }

        int pixels = frame.length * frame[0].length;

        for (i = 0; i < frame.length; i++) {
            for (j = 0; j < frame[i].length; j++) {
                frameElement = frame[i][j];

                if ((frameElement < 0) || (frameElement > 255)) {
                    throw new IllegalActionException("ImageContrast:"
                            + "input image pixel contains at" + j + "," + i
                            + "with value" + frameElement
                            + "that is out of bounds."
                            + " Not between 0 and 255.");
                }

                colorHistogram[frameElement]++;
            }
        }

        //Construct the cdf of the color distribution histogram
        //colorHistogram[0] = colorHistogram[0]
        for (i = 1; i < 256; i++) {
            colorHistogram[i] = colorHistogram[i - 1] + colorHistogram[i];
        }

        // Search each pixel in the image and re-map it to a new
        // color number to make a new relatively even color distribution
        // image.
        int distributionConstant = pixels / 255;

        for (i = 0; i < frame.length; i++) {
            for (j = 0; j < frame[i].length; j++) {
                frameElement = frame[i][j];
                frame[i][j] = colorHistogram[frameElement]
                        / distributionConstant;
            }
        }

        message = new IntMatrixToken(frame);
        output.send(0, message);
    }
View Full Code Here

        Token[] _partitions = input.get(0, _partitionCount);

        for (j = 0, partitionNumber = 0; j < _imageRows; j += _partitionRows) {
            for (i = 0; i < _imageColumns; i += _partitionColumns, partitionNumber++) {
                IntMatrixToken partition = (IntMatrixToken) _partitions[partitionNumber];

                if ((partition.getRowCount() != _partitionRows)
                        || (partition.getColumnCount() != _partitionColumns)) {
                    throw new IllegalActionException(
                            "input data must be partitionRows "
                                    + "by partitionColumns");
                }

                int[][] part = partition.intMatrix();

                for (y = 0; y < _partitionRows; y++) {
                    System.arraycopy(part[y], 0, _image[j + y], i,
                            _partitionColumns);
                }
            }
        }

        output.send(0, new IntMatrixToken(_image));
    }
View Full Code Here

        int element1;
        int element2;

        double PSNRValue;

        IntMatrixToken signalToken = (IntMatrixToken) signal.get(0);
        IntMatrixToken distortedSignalToken = (IntMatrixToken) distortedSignal
                .get(0);
        int columns = signalToken.getColumnCount();
        int rows = signalToken.getRowCount();

        if ((distortedSignalToken.getColumnCount() != columns)
                || (distortedSignalToken.getRowCount() != rows)) {
            throw new IllegalActionException("Input token dimensions "
                    + "must match!");
        }

        for (j = 0; j < rows; j++) {
            for (i = 0; i < columns; i++) {
                element1 = signalToken.getElementAt(j, i);
                element2 = distortedSignalToken.getElementAt(j, i);

                signalPower = signalPower + (element1 * element1);
                noisePower = noisePower
                        + ((element1 - element2) * (element1 - element2));
            }
View Full Code Here

                    for (j = 0; j < _imageColumns; j++, n++) {
                        _frameInts[i][j] = _frameBytes[n] & 255;
                    }
                }

                _images[_frameNumber] = new IntMatrixToken(_frameInts);
            } catch (IllegalActionException ex) {
                _images = null;
                throw new IllegalActionException(this, ex,
                        "Failed to initialize");
            } catch (Exception ex) {
View Full Code Here

        int j;
        int stage = _stages(_blockWidth * _blockHeight);
        _codewords = input.get(0, _blockCount);

        for (j = 0; j < _blockCount; j++) {
            _blocks[j] = new IntMatrixToken(
                    _codebook[stage][((IntToken) _codewords[j]).intValue()]);
        }

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

        try {
            SizeAttribute vergilSize = (SizeAttribute) _model
                    .getAttribute("_vergilSize");

            IntMatrixToken vergilSizeToken = (IntMatrixToken) vergilSize
                    .getToken();

            vergilWidth = vergilSizeToken.getElementAt(0, 0);
            vergilHeight = vergilSizeToken.getElementAt(0, 1);
        } catch (Exception ex) {
            System.out.println("Warning: Failed to get vergil width "
                    + "and height, using defaults: " + ex.getMessage());
        }
View Full Code Here

                            for (int j = 0; j < a[0].length; j++) {
                                tmp[i][j] = (int) a[i][j];
                            }
                        }

                        retval = new IntMatrixToken(tmp);
                    } else {
                        retval = new DoubleMatrixToken(a);
                    }
                }
            }
        } else if (maClassStr.equals("logical")) {
            int[][] a = ptmatlabGetLogicalMatrix(ma, nRows, nCols);

            if (a == null) {
                throw new IllegalActionException(
                        "can't get logical matrix from matlab engine.");
            }

            if (scalarMatrices) {
                retval = new IntToken(a[0][0]);
            } else {
                retval = new IntMatrixToken(a);
            }
        } else if (maClassStr.equals("struct")) {
            int nfields = ptmatlabGetNumberOfFields(ma);
            Token[] ta = new Token[nCols];
            Token[] tr = new Token[nRows];
View Full Code Here

        } else if (object instanceof String) {
            returnValue = new StringToken((String) object);
        } else if (object instanceof boolean[][]) {
            returnValue = new BooleanMatrixToken((boolean[][]) object);
        } else if (object instanceof int[][]) {
            returnValue = new IntMatrixToken((int[][]) object);
        } else if (object instanceof long[][]) {
            returnValue = new LongMatrixToken((long[][]) object);
        } else if (object instanceof double[][]) {
            returnValue = new DoubleMatrixToken((double[][]) object);
        } else if (object instanceof Complex[][]) {
View Full Code Here

                // The following conversion will fail if the member cannot
                // be converted to an int.
                IntToken singleMember = IntToken.convert(token);
                int[] matrix = new int[1];
                matrix[0] = singleMember.intValue();
                return new IntMatrixToken(matrix, 1, 1);
            }
        }
View Full Code Here

TOP

Related Classes of ptolemy.data.IntMatrixToken

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.