Search in sources :

Example 1 with ImagePortObjectSpec

use of org.knime.core.node.port.image.ImagePortObjectSpec in project knime-core by knime.

the class ImageToTableNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    ImagePortObjectSpec inspec = (ImagePortObjectSpec) inSpecs[0];
    DataTableSpec outspec = createResultSpec(inspec, m_columnNameModel.getStringValue());
    return new DataTableSpec[] { outspec };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ImagePortObjectSpec(org.knime.core.node.port.image.ImagePortObjectSpec)

Example 2 with ImagePortObjectSpec

use of org.knime.core.node.port.image.ImagePortObjectSpec in project knime-core by knime.

the class WritePNGNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    String outPath = m_fileOutSettings.getStringValue();
    boolean overwriteOK = m_overwriteOKBoolean.getBooleanValue();
    if (outPath == null || outPath.length() == 0) {
        throw new InvalidSettingsException("No output path specified");
    }
    File f = new File(outPath);
    if (f.isDirectory()) {
        throw new InvalidSettingsException("Can't write to \"" + outPath + "\": it is a directory");
    }
    if (f.isFile() && !overwriteOK) {
        throw new InvalidSettingsException("Can't write to \"" + outPath + "\": file exists (configure overwrite in dialog)");
    }
    File directory = f.getParentFile();
    if (directory == null || !directory.isDirectory()) {
        throw new InvalidSettingsException("Can't write to \"" + outPath + "\": parent directory does not exist");
    }
    ImagePortObjectSpec imageInObject = (ImagePortObjectSpec) inSpecs[0];
    DataType dataType = imageInObject.getDataType();
    if (!dataType.isCompatible(PNGImageValue.class)) {
        throw new InvalidSettingsException("Unsupported image type, " + "expecting PNG input, got " + dataType);
    }
    return new PortObjectSpec[0];
}
Also used : ImagePortObjectSpec(org.knime.core.node.port.image.ImagePortObjectSpec) PNGImageValue(org.knime.core.data.image.png.PNGImageValue) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ImagePortObjectSpec(org.knime.core.node.port.image.ImagePortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) DataType(org.knime.core.data.DataType) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) File(java.io.File)

Example 3 with ImagePortObjectSpec

use of org.knime.core.node.port.image.ImagePortObjectSpec in project knime-core by knime.

the class TableRowToImageNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
    String column = m_imageColSettingsModel.getStringValue();
    int columnIndex = inSpec.findColumnIndex(column);
    if (columnIndex < 0) {
        columnIndex = findImageColumnIndex(inSpec);
        if (columnIndex >= 0) {
            setWarningMessage("Found image column '" + inSpec.getColumnSpec(columnIndex).getName() + "'.");
        }
    }
    if (columnIndex < 0) {
        String error = column == null ? "No image column in input" : "No such image column in input table: " + column;
        throw new InvalidSettingsException(error);
    }
    DataColumnSpec columnSpec = inSpec.getColumnSpec(columnIndex);
    if (!columnSpec.getType().isCompatible(ImageValue.class)) {
        throw new InvalidSettingsException("Column \"" + column + "\" does not contain images");
    }
    return new PortObjectSpec[] { new ImagePortObjectSpec(columnSpec.getType()) };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) ImagePortObjectSpec(org.knime.core.node.port.image.ImagePortObjectSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ImagePortObjectSpec(org.knime.core.node.port.image.ImagePortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) ImageValue(org.knime.core.data.image.ImageValue)

Example 4 with ImagePortObjectSpec

use of org.knime.core.node.port.image.ImagePortObjectSpec in project knime-core by knime.

the class TableRowToImageNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    BufferedDataTable inTable = (BufferedDataTable) inObjects[0];
    // check for empty table
    if (inTable.size() == 0) {
        throw new IllegalArgumentException("Input table is empty.");
    }
    // warn if more than one row
    if (inTable.size() > 1) {
        setWarningMessage("Input data table has more than one rows! " + "Using first row only.");
    }
    String column = m_imageColSettingsModel.getStringValue();
    DataTableSpec inSpec = inTable.getDataTableSpec();
    int columnIndex = inSpec.findColumnIndex(column);
    if (columnIndex < 0) {
        columnIndex = findImageColumnIndex(inSpec);
    }
    ImagePortObjectSpec imagePortObjectSpec = new ImagePortObjectSpec(inSpec.getColumnSpec(columnIndex).getType());
    final RowIterator it = inTable.iterator();
    while (it.hasNext()) {
        DataRow row = it.next();
        DataCell cell = row.getCell(columnIndex);
        if (!cell.isMissing()) {
            ImageContent ic = ((ImageValue) cell).getImageContent();
            return new PortObject[] { new ImagePortObject(ic, imagePortObjectSpec) };
        } else {
            setWarningMessage("Found missing image cell, skipping it...");
        }
    }
    throw new IllegalArgumentException("Input table contains only missing cells.");
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ImagePortObjectSpec(org.knime.core.node.port.image.ImagePortObjectSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) ImagePortObject(org.knime.core.node.port.image.ImagePortObject) DataRow(org.knime.core.data.DataRow) ImageContent(org.knime.core.data.image.ImageContent) RowIterator(org.knime.core.data.RowIterator) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) ImageValue(org.knime.core.data.image.ImageValue) PortObject(org.knime.core.node.port.PortObject) ImagePortObject(org.knime.core.node.port.image.ImagePortObject)

Example 5 with ImagePortObjectSpec

use of org.knime.core.node.port.image.ImagePortObjectSpec in project knime-core by knime.

the class WriteImageNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    ImagePortObjectSpec imageInObject = (ImagePortObjectSpec) inSpecs[0];
    DataType dataType = imageInObject.getDataType();
    if (!dataType.isCompatible(ImageValue.class)) {
        throw new InvalidSettingsException("Unsupported image type");
    }
    // how ugly - we don't know the image extension upon execution, let's
    // hope the user gave it the correct extension (e.g. ".png") already,
    // otherwise the overwriteOK check may fail during configure
    String guessedExtension;
    if (dataType.isCompatible(PNGImageValue.class)) {
        guessedExtension = ".png";
    } else if (dataType.getPreferredValueClass().getSimpleName().equals("SvgImageValue")) {
        guessedExtension = ".svg";
    } else {
        guessedExtension = "";
    }
    getOutputLocation(guessedExtension, true);
    return new PortObjectSpec[0];
}
Also used : ImagePortObjectSpec(org.knime.core.node.port.image.ImagePortObjectSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ImagePortObjectSpec(org.knime.core.node.port.image.ImagePortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) DataType(org.knime.core.data.DataType) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) PNGImageValue(org.knime.core.data.image.png.PNGImageValue) ImageValue(org.knime.core.data.image.ImageValue)

Aggregations

ImagePortObjectSpec (org.knime.core.node.port.image.ImagePortObjectSpec)7 DataTableSpec (org.knime.core.data.DataTableSpec)4 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)4 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)4 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)4 ImageValue (org.knime.core.data.image.ImageValue)3 DataColumnSpec (org.knime.core.data.DataColumnSpec)2 DataRow (org.knime.core.data.DataRow)2 DataType (org.knime.core.data.DataType)2 PNGImageValue (org.knime.core.data.image.png.PNGImageValue)2 BufferedDataTable (org.knime.core.node.BufferedDataTable)2 PortObject (org.knime.core.node.port.PortObject)2 ImagePortObject (org.knime.core.node.port.image.ImagePortObject)2 Graphics2D (java.awt.Graphics2D)1 GraphicsConfiguration (java.awt.GraphicsConfiguration)1 GraphicsEnvironment (java.awt.GraphicsEnvironment)1 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1