Search in sources :

Example 1 with ImageSegment

use of org.codice.imaging.nitf.core.image.ImageSegment in project alliance by codice.

the class ImageInputTransformerTest method createNitfWithAimidb.

private static Map<NitfAttribute, NitfValue> createNitfWithAimidb(File file) {
    String acquisitionDate = "20161013121212";
    String missionNumber = "UNKN";
    String country = "US";
    String location = "4559N23345W";
    Tre aimidb = TreFactory.getDefault("AIMIDB", TreSource.ImageExtendedSubheaderData);
    aimidb.add(new TreEntryImpl("ACQUISITION_DATE", acquisitionDate, "string"));
    aimidb.add(new TreEntryImpl("MISSION_NO", missionNumber, "string"));
    aimidb.add(new TreEntryImpl("MISSION_IDENTIFICATION", "NOT AVAIL.", "string"));
    aimidb.add(new TreEntryImpl("FLIGHT_NO", "01", "string"));
    aimidb.add(new TreEntryImpl("OP_NUM", "001", "UINT"));
    aimidb.add(new TreEntryImpl("CURRENT_SEGMENT", "AA", "string"));
    aimidb.add(new TreEntryImpl("REPRO_NUM", "01", "UINT"));
    aimidb.add(new TreEntryImpl("REPLAY", "000", "string"));
    aimidb.add(new TreEntryImpl("RESERVED_1", " ", "string"));
    aimidb.add(new TreEntryImpl("START_TILE_COLUMN", "001", "UINT"));
    aimidb.add(new TreEntryImpl("START_TILE_ROW", "00001", "UINT"));
    aimidb.add(new TreEntryImpl("END_SEGMENT", "AA", "string"));
    aimidb.add(new TreEntryImpl("END_TILE_COLUMN", "001", "UINT"));
    aimidb.add(new TreEntryImpl("END_TILE_ROW", "00001", "UINT"));
    aimidb.add(new TreEntryImpl("COUNTRY", country, "string"));
    aimidb.add(new TreEntryImpl("RESERVED_2", "    ", "string"));
    aimidb.add(new TreEntryImpl("LOCATION", location, "string"));
    aimidb.add(new TreEntryImpl("RESERVED_3", "             ", "string"));
    ImageSegment imageSegment = TreUtilityTest.createImageSegment();
    imageSegment.getTREsRawStructure().add(aimidb);
    new NitfCreationFlowImpl().fileHeader(() -> TreUtilityTest.createFileHeader()).imageSegment(() -> imageSegment).write(file.getAbsolutePath());
    // key value pair of nitf attributes and expected getAttributes
    Map<NitfAttribute, NitfValue> assertMap = new HashMap<>();
    assertMap.put(AimidbAttribute.ACQUISITION_DATE_ATTRIBUTE, new NitfValue(acquisitionDate));
    assertMap.put(AimidbAttribute.MISSION_NUMBER_ATTRIBUTE, new NitfValue(missionNumber));
    assertMap.put(AimidbAttribute.COUNTRY_CODE_ATTRIBUTE, new NitfValue(country));
    assertMap.put(AimidbAttribute.LOCATION_ATTRIBUTE, new NitfValue(location));
    return assertMap;
}
Also used : TreUtilityTest.createImageSegment(org.codice.alliance.transformer.nitf.TreUtilityTest.createImageSegment) ImageSegment(org.codice.imaging.nitf.core.image.ImageSegment) NitfCreationFlowImpl(org.codice.imaging.nitf.fluent.impl.NitfCreationFlowImpl) HashMap(java.util.HashMap) Tre(org.codice.imaging.nitf.core.tre.Tre) NitfAttribute(org.codice.alliance.transformer.nitf.common.NitfAttribute) TreEntryImpl(org.codice.imaging.nitf.core.tre.impl.TreEntryImpl)

Example 2 with ImageSegment

use of org.codice.imaging.nitf.core.image.ImageSegment in project alliance by codice.

the class ImageInputTransformerTest method createNitfWithCsexra.

private static void createNitfWithCsexra(File file) {
    NitfHeader header = NitfHeaderFactory.getDefault(FileType.NITF_TWO_ONE);
    Tre csexra = TreFactory.getDefault("CSEXRA", TreSource.ImageExtendedSubheaderData);
    csexra.add(new TreEntryImpl("SNOW_DEPTH_CAT", "1", "string"));
    csexra.add(new TreEntryImpl("SENSOR", str(6), "string"));
    csexra.add(new TreEntryImpl("TIME_FIRST_LINE_IMAGE", "12345.000000", "string"));
    csexra.add(new TreEntryImpl("TIME_IMAGE_DURATION", "12345.000000", "string"));
    csexra.add(new TreEntryImpl("MAX_GSD", "123.5", "string"));
    csexra.add(new TreEntryImpl("ALONG_SCAN_GSD", "123.5", "string"));
    csexra.add(new TreEntryImpl("CROSS_SCAN_GSD", "123.5", "string"));
    csexra.add(new TreEntryImpl("GEO_MEAN_GSD", "123.5", "string"));
    csexra.add(new TreEntryImpl("A_S_VERT_GSD", "123.5", "string"));
    csexra.add(new TreEntryImpl("C_S_VERT_GSD", "123.5", "string"));
    csexra.add(new TreEntryImpl("GEO_MEAN_VERT_GSD", "123.5", "string"));
    csexra.add(new TreEntryImpl("GSD_BETA_ANGLE", "123.5", "string"));
    csexra.add(new TreEntryImpl("DYNAMIC_RANGE", "02047", "string"));
    csexra.add(new TreEntryImpl("NUM_LINES", "0000101", "string"));
    csexra.add(new TreEntryImpl("NUM_SAMPLES", "00101", "string"));
    csexra.add(new TreEntryImpl("ANGLE_TO_NORTH", "000.000", "string"));
    csexra.add(new TreEntryImpl("OBLIQUITY_ANGLE", "00.000", "string"));
    csexra.add(new TreEntryImpl("AZ_OF_OBLIQUITY", "000.000", "string"));
    csexra.add(new TreEntryImpl("GRD_COVER", "1", "string"));
    csexra.add(new TreEntryImpl("SNOW_DEPTH_CAT", "1", "string"));
    csexra.add(new TreEntryImpl("SUN_AZIMUTH", "000.000", "string"));
    csexra.add(new TreEntryImpl("SUN_ELEVATION", "-90.000", "string"));
    csexra.add(new TreEntryImpl("PREDICTED_NIIRS", "1.0", "string"));
    csexra.add(new TreEntryImpl("CIRCL_ERR", "000", "string"));
    csexra.add(new TreEntryImpl("LINEAR_ERR", "000", "string"));
    ImageSegment imageSegment = ImageSegmentFactory.getDefault(FileType.NITF_TWO_ONE);
    imageSegment.addImageBand(TreUtilityTest.createImageBand());
    imageSegment.getTREsRawStructure().add(csexra);
    new NitfCreationFlowImpl().fileHeader(() -> header).imageSegment(() -> imageSegment).write(file.getAbsolutePath());
}
Also used : TreUtilityTest.createImageSegment(org.codice.alliance.transformer.nitf.TreUtilityTest.createImageSegment) ImageSegment(org.codice.imaging.nitf.core.image.ImageSegment) NitfCreationFlowImpl(org.codice.imaging.nitf.fluent.impl.NitfCreationFlowImpl) NitfHeader(org.codice.imaging.nitf.core.header.NitfHeader) Tre(org.codice.imaging.nitf.core.tre.Tre) TreEntryImpl(org.codice.imaging.nitf.core.tre.impl.TreEntryImpl)

Example 3 with ImageSegment

use of org.codice.imaging.nitf.core.image.ImageSegment in project alliance by codice.

the class ImageInputTransformerTest method createNitfWithPiaimc.

private static void createNitfWithPiaimc(File file) {
    NitfHeader header = NitfHeaderFactory.getDefault(FileType.NITF_TWO_ONE);
    Tre piaimc = TreFactory.getDefault("PIAIMC", TreSource.ImageExtendedSubheaderData);
    piaimc.add(new TreEntryImpl("CLOUDCVR", "070", "string"));
    piaimc.add(new TreEntryImpl("SRP", "Y", "string"));
    piaimc.add(new TreEntryImpl("SENSMODE", str(12), "string"));
    piaimc.add(new TreEntryImpl("SENSNAME", str(18), "string"));
    piaimc.add(new TreEntryImpl("SOURCE", str(255), "string"));
    piaimc.add(new TreEntryImpl("COMGEN", "09", "string"));
    piaimc.add(new TreEntryImpl("SUBQUAL", str(1), "string"));
    piaimc.add(new TreEntryImpl("PIAMSNNUM", str(7), "string"));
    piaimc.add(new TreEntryImpl("CAMSPECS", str(32), "string"));
    piaimc.add(new TreEntryImpl("PROJID", str(2), "string"));
    piaimc.add(new TreEntryImpl("GENERATION", "8", "string"));
    piaimc.add(new TreEntryImpl("ESD", "Y", "string"));
    piaimc.add(new TreEntryImpl("OTHERCOND", str(2), "string"));
    piaimc.add(new TreEntryImpl("MEANGSD", "00000.0", "string"));
    piaimc.add(new TreEntryImpl("IDATUM", str(3), "string"));
    piaimc.add(new TreEntryImpl("IELLIP", str(3), "string"));
    piaimc.add(new TreEntryImpl("PREPROC", str(2), "string"));
    piaimc.add(new TreEntryImpl("IPROJ", str(2), "string"));
    piaimc.add(new TreEntryImpl("SATTRACK_PATH", "0000", "string"));
    piaimc.add(new TreEntryImpl("SATTRACK_ROW", "0000", "string"));
    ImageSegment imageSegment = ImageSegmentFactory.getDefault(FileType.NITF_TWO_ONE);
    imageSegment.addImageBand(TreUtilityTest.createImageBand());
    imageSegment.getTREsRawStructure().add(piaimc);
    new NitfCreationFlowImpl().fileHeader(() -> header).imageSegment(() -> imageSegment).write(file.getAbsolutePath());
}
Also used : TreUtilityTest.createImageSegment(org.codice.alliance.transformer.nitf.TreUtilityTest.createImageSegment) ImageSegment(org.codice.imaging.nitf.core.image.ImageSegment) NitfCreationFlowImpl(org.codice.imaging.nitf.fluent.impl.NitfCreationFlowImpl) NitfHeader(org.codice.imaging.nitf.core.header.NitfHeader) Tre(org.codice.imaging.nitf.core.tre.Tre) TreEntryImpl(org.codice.imaging.nitf.core.tre.impl.TreEntryImpl)

Example 4 with ImageSegment

use of org.codice.imaging.nitf.core.image.ImageSegment in project alliance by codice.

the class CatalogOutputAdapter method createChipImageSegment.

private ImageSegment createChipImageSegment(BufferedImage chip, int sourceX, int sourceY, NitfSegmentsFlow nitfSegmentsFlow) throws IOException, NitfFormatException {
    List<ImageSegment> originalImageSegments = getImageSegments(nitfSegmentsFlow);
    if (originalImageSegments.isEmpty()) {
        throw new IOException("expected at least one image segment in nitf");
    }
    ImageSegment originalImageSegment = originalImageSegments.get(0);
    ImageSegment chipImageSegment = ImageSegmentFactory.getDefault(FileType.NITF_TWO_ONE);
    chipImageSegment.setImageCategory(originalImageSegment.getImageCategory());
    int numberOfBlocksPerColumn;
    int numberOfBlocksPerRow;
    int numberOfPixelsPerBlockHorizontalRaw;
    int numberOfPixelsPerBlockVerticalRaw;
    boolean isBlocking;
    if (chip.getWidth() > BLOCK_WIDTH || chip.getHeight() > BLOCK_HEIGHT) {
        numberOfBlocksPerRow = (int) Math.ceil((double) chip.getWidth() / BLOCK_WIDTH);
        numberOfBlocksPerColumn = (int) Math.ceil((double) chip.getHeight() / BLOCK_HEIGHT);
        numberOfPixelsPerBlockHorizontalRaw = BLOCK_WIDTH;
        numberOfPixelsPerBlockVerticalRaw = BLOCK_HEIGHT;
        isBlocking = true;
    } else {
        numberOfBlocksPerColumn = 1;
        numberOfBlocksPerRow = 1;
        numberOfPixelsPerBlockHorizontalRaw = 0;
        numberOfPixelsPerBlockVerticalRaw = 0;
        isBlocking = false;
    }
    originalImageSegment.getImageComments().forEach(chipImageSegment::addImageComment);
    chipImageSegment.setNumberOfBlocksPerColumn(numberOfBlocksPerColumn);
    chipImageSegment.setNumberOfBlocksPerRow(numberOfBlocksPerRow);
    chipImageSegment.setIdentifier(originalImageSegment.getIdentifier());
    chipImageSegment.setImageIdentifier2(originalImageSegment.getImageIdentifier2());
    chipImageSegment.setImageMagnification(originalImageSegment.getImageMagnification());
    chipImageSegment.setImageTargetId(originalImageSegment.getImageTargetId());
    chipImageSegment.setImageSource(originalImageSegment.getImageSource());
    chipImageSegment.setNumberOfColumns(chip.getWidth());
    chipImageSegment.setNumberOfRows(chip.getHeight());
    chipImageSegment.setNumberOfPixelsPerBlockHorizontalRaw(numberOfPixelsPerBlockHorizontalRaw);
    chipImageSegment.setNumberOfPixelsPerBlockVerticalRaw(numberOfPixelsPerBlockVerticalRaw);
    chipImageSegment.setImageDateTime(originalImageSegment.getImageDateTime());
    setImageCoordinates(sourceX, sourceY, chip.getWidth(), chip.getHeight(), chipImageSegment, originalImageSegment);
    chipImageSegment.setPixelJustification(PixelJustification.RIGHT);
    chipImageSegment.setImageDisplayLevel(DEFAULT_DISPLAY_LEVEL);
    chipImageSegment.setImageLocationRow(0);
    chipImageSegment.setImageLocationColumn(0);
    setImageDataFields(chip, chipImageSegment);
    setImageData(chip, chipImageSegment, isBlocking, numberOfPixelsPerBlockHorizontalRaw, numberOfPixelsPerBlockVerticalRaw);
    chipImageSegment.setUserDefinedHeaderOverflow(0);
    chipImageSegment.setSecurityMetadata(originalImageSegment.getSecurityMetadata());
    return chipImageSegment;
}
Also used : ImageSegment(org.codice.imaging.nitf.core.image.ImageSegment) IOException(java.io.IOException)

Example 5 with ImageSegment

use of org.codice.imaging.nitf.core.image.ImageSegment in project alliance by codice.

the class CatalogOutputAdapter method getNitfBinaryContent.

/**
 * Create a NITF of a chip that extracted from another NITF.
 *
 * @param chip the image data for the chipped area
 * @param nitfSegmentsFlow the segments from the original nitf
 * @param sourceX the x pixel coordinates of the original nitf where the chip was extracted
 * @param sourceY the y pixel coordinates of the original nitf where the chip was extracted
 * @return a nitf file containing the chip
 */
@SuppressWarnings("unused")
public BinaryContent getNitfBinaryContent(BufferedImage chip, NitfSegmentsFlow nitfSegmentsFlow, int sourceX, int sourceY) throws IOException, MimeTypeParseException, NitfFormatException {
    try {
        NitfHeader chipHeader = createChipHeader(nitfSegmentsFlow);
        nitfSegmentsFlow.fileHeader(nitfHeader -> copySDEs(nitfHeader, chipHeader));
        ImageSegment chipImageSegment = createChipImageSegment(chip, sourceX, sourceY, nitfSegmentsFlow);
        addIchipbTre(chip, sourceX, sourceY, chipImageSegment);
        List<ImageSegment> imageSegments = getImageSegments(nitfSegmentsFlow);
        if (!imageSegments.isEmpty()) {
            copySDEs(imageSegments.get(0), chipImageSegment);
        }
        return nitfToBinaryContent(chipHeader, chipImageSegment);
    } finally {
        nitfSegmentsFlow.end();
    }
}
Also used : ImageSegment(org.codice.imaging.nitf.core.image.ImageSegment) NitfHeader(org.codice.imaging.nitf.core.header.NitfHeader)

Aggregations

ImageSegment (org.codice.imaging.nitf.core.image.ImageSegment)15 NitfHeader (org.codice.imaging.nitf.core.header.NitfHeader)7 TreUtilityTest.createImageSegment (org.codice.alliance.transformer.nitf.TreUtilityTest.createImageSegment)6 Tre (org.codice.imaging.nitf.core.tre.Tre)6 TreEntryImpl (org.codice.imaging.nitf.core.tre.impl.TreEntryImpl)6 NitfCreationFlowImpl (org.codice.imaging.nitf.fluent.impl.NitfCreationFlowImpl)6 TargetIdImpl (org.codice.imaging.nitf.core.image.impl.TargetIdImpl)4 FileSecurityMetadata (org.codice.imaging.nitf.core.security.FileSecurityMetadata)4 SecurityMetadata (org.codice.imaging.nitf.core.security.SecurityMetadata)4 NitfParserInputFlowImpl (org.codice.imaging.nitf.fluent.impl.NitfParserInputFlowImpl)4 BufferedImage (java.awt.image.BufferedImage)3 HashMap (java.util.HashMap)3 NitfAttribute (org.codice.alliance.transformer.nitf.common.NitfAttribute)3 NitfFormatException (org.codice.imaging.nitf.core.common.NitfFormatException)3 NitfSegmentsFlow (org.codice.imaging.nitf.fluent.NitfSegmentsFlow)3 Test (org.junit.Test)3 BinaryContent (ddf.catalog.data.BinaryContent)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 DataSource (org.codice.imaging.nitf.core.DataSource)2