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;
}
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());
}
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());
}
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;
}
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();
}
}
Aggregations