public final class Patch extends Displayable implements ImageData
Modifier and Type | Class and Description |
---|---|
static class |
Patch.PatchImage |
static class |
Patch.TransformProperties |
Displayable.DataPackage, Displayable.DoEdit, Displayable.DoEdits, Displayable.DoTransforms, Displayable.SliderListener
Modifier and Type | Field and Description |
---|---|
static DirectColorModel |
DCM |
protected int |
meshResolution |
alpha, annotation, at, color, COMPOSITE_ADD, COMPOSITE_COLOR_YCBCR, COMPOSITE_DIFFERENCE, COMPOSITE_MULTIPLY, COMPOSITE_NORMAL, COMPOSITE_SUBTRACT, compositeModes, height, hs_linked, last_color, layer, linked_props, linked_props_origins, locked, props, TAG_ATTR1, TAG_ATTR2, title, visible, width
Constructor and Description |
---|
Patch(Project project,
long id,
HashMap<String,String> ht_attributes,
HashMap<Displayable,String> ht_links)
Reconstruct from an XML entry.
|
Patch(Project project,
long id,
String title,
float width,
float height,
int o_width,
int o_height,
int type,
boolean locked,
double min,
double max,
AffineTransform at)
Reconstruct a Patch from the database.
|
Patch(Project project,
String title,
double x,
double y,
ij.ImagePlus imp)
Construct a Patch from an image;
most likely you will need to add the file path to the
imp
by calling Loader.addedPatchFrom(String, Patch) , as in this example:
project.getLoader().addedPatchFrom("/path/to/file.png", thePatch); |
Patch(Project project,
String title,
float width,
float height,
int o_width,
int o_height,
int type,
float alpha,
Color color,
boolean locked,
double min,
double max,
AffineTransform at,
String file_path)
Create a new Patch defining all necessary parameters; it is the responsibility
of the caller to ensure that the parameters are in agreement with the image
contained in the
file_path . |
Modifier and Type | Method and Description |
---|---|
void |
addAlphaMask(Area aw,
int value)
Add the given area, in world coords, to the alpha mask, using the given fill value.
|
void |
addAlphaMask(Roi roi,
int value)
Add the given roi, in world coords, to the alpha mask, using the given fill value.
|
void |
addAlphaMaskLocal(Area aLocal,
int value)
Add the given area, in local coordinates, to the alpha mask, using the given fill value.
|
Image |
adjustChannels(Image awt)
Takes an image and scales its channels according to the values packed in this.channels.
|
void |
appendCoordinateTransform(CoordinateTransform ct)
Append a
CoordinateTransform to the current
CoordinateTransformList . |
void |
appendFilters(IFilter[] fs)
|
protected void |
approximateTransferPixel(int[] pvalue)
Transfer an 8-bit or RGB pixel to this image color space, interpolating;
the pvalue is modified in place.
|
void |
cacheCurrentPath(String path)
Cache a proper, good, known path to the image wrapped by this Patch.
|
boolean |
checkAlphaMaskFile() |
boolean |
checkCoordinateTransformFile() |
boolean |
clearIntensityMap() |
Displayable |
clone(Project pr,
boolean copy_id)
Performs a copy of this object, without the links, unlocked and visible, except for the image which is NOT duplicated.
|
boolean |
contains(double x_p,
double y_p)
Considers the alpha mask.
|
Patch.PatchImage |
createCoordinateTransformedImage() |
Image |
createImage() |
Image |
createImage(ij.ImagePlus imp) |
static Patch |
createPatch(Project project,
String filepath)
Create a new Patch and register the associated
filepath
with the project's loader. |
Patch.PatchImage |
createTransformedImage()
Returns a PatchImage object containing the bottom-of-transformation-stack image and alpha mask, if any (except the AffineTransform, which is used for direct hw-accel screen rendering).
|
protected static void |
crosslink(Collection<Displayable> patches,
boolean overlapping_only) |
void |
debug() |
static void |
exportDTD(StringBuilder sb_header,
HashSet<String> hs,
String indent) |
void |
exportXML(StringBuilder sb_body,
String indent,
XMLOptions options)
Opens and closes the tag and exports data.
|
CoordinateTransform |
fetchCoordinateTransform()
Read in the
CoordinateTransform from a file whose name is crafted
from the ct_id and this Patch 's DBObject.id . |
ij.process.ByteProcessor |
getAlphaMask()
Return a new
ByteProcessor representing the alpha mask, if any, over the pixel data. |
String |
getAlphaMaskFilePath() |
long |
getAlphaMaskId() |
Area |
getArea()
Returns an Area in world coords representing the inside of this Patch.
|
protected Area |
getAreaForBucket(Layer l)
Use this instead of getAreaAt which calls getArea which is ...
|
int |
getChannelAlphas() |
CoordinateTransform |
getCoordinateTransform()
Obtain a copy of the
CoordinateTransform that transfers image data to mipmap image data. |
Rectangle |
getCoordinateTransformBoundingBox()
Get the bounding rectangle of the transformed image relative to the
original image.
|
protected static Rectangle |
getCoordinateTransformBoundingBox(Patch p,
CoordinateTransform ct)
Allow reusing a
CoordinateTransform that was already loaded from a file. |
String |
getCoordinateTransformFilePath() |
long |
getCoordinateTransformId()
A value of 0 indicates that there isn't one.
|
String |
getCurrentPath()
Returns the value of the field current_path, which may be null.
|
String |
getFilePath()
If this patch is part of a stack, the file path will contain the slice number attached to it, in the form -----#slice=10 for slice number 10.
|
IFilter[] |
getFilters() |
CoordinateTransform |
getFullCoordinateTransform()
Create a
CoordinateTransform that incorporates both the
CoordinateTransform of this Patch (if present) and its
AffineTransform . |
String |
getImageFilePath()
Returns the absolute path to the image file, as read by the OS.
|
ij.ImagePlus |
getImagePlus()
Fetches the ImagePlus from the cache; be warned: the returned ImagePlus may have been flushed, removed and then recreated if the program had memory needs that required flushing part of the cache; use @getImageProcessor to get the pixels guaranteed not to be ever null.
|
ij.process.ImageProcessor |
getImageProcessor()
Fetches the ImageProcessor from the cache, which will never be flushed or its pixels set to null.
|
AffineTransform |
getLocalAffine(double wx,
double wy)
Return the local affine transformation for a passed location in world
coordinates.
|
double |
getLocalScale(double wx,
double wy) |
double |
getMax() |
int |
getMeshResolution() |
double |
getMin() |
int |
getOHeight()
The original height of the pixels in the source image file.
|
String |
getOriginalPath()
Returns the value of the field original_path, which may be null.
|
int |
getOWidth()
The original width of the pixels in the source image file.
|
int |
getPixel(double mag,
int x,
int y)
Magnification-dependent counterpart to ImageProcessor.getPixel(x, y).
|
int[] |
getPixel(double mag,
int x,
int y,
int[] iArray)
Magnification-dependent counterpart to ImageProcessor.getPixel(x, y, iArray).
|
int[] |
getPixel(int x,
int y,
double mag)
Expects x,y in world coordinates.
|
String |
getPreprocessorScriptPath() |
ArrayList<Patch> |
getStackPatches() |
Patch.TransformProperties |
getTransformPropertiesCopy() |
int |
getType()
Returns the ImagePlus type of this Patch.
|
boolean |
hasAlphaChannel()
Whether there is an alpha mask or there is an outside mask caused by a
CoordinateTransform . |
boolean |
hasAlphaMask()
Whether there is an alpha mask for the pixel data.
|
boolean |
hasCoordinateTransform() |
boolean |
intersects(Displayable d)
Check if this perimeter's intersects that of the given Displayable.
|
boolean |
intersects(Displayable d,
boolean sloppy) |
boolean |
isDeletable() |
boolean |
isPreprocessed() |
protected boolean |
isRoughlyInside(Layer l,
Rectangle r)
If this Displayable intersects with @param r or almost intersects, then returns true.
|
boolean |
isStack()
Returns true if this Patch holds direct links to at least one other image in a different layer.
|
void |
keyPressed(KeyEvent ke) |
boolean |
linkPatches()
Override to cancel.
|
static ij.process.ImageProcessor |
makeFlatGrayImage(List<Patch> patches,
Rectangle finalBox,
int backgroundValue,
double scale)
Deprecated.
|
static ij.process.ImageProcessor |
makeFlatImage(int type,
Layer layer,
Rectangle srcRect,
double scale,
Collection<Patch> patches,
Color background)
Defaults to setMinAndMax = true.
|
static ij.process.ImageProcessor |
makeFlatImage(int type,
Layer layer,
Rectangle srcRect,
double scale,
Collection<Patch> patches,
Color background,
boolean setMinAndMax)
Creates an ImageProcessor of the specified type.
|
PatchStack |
makePatchStack()
Retuns a virtual ImagePlus with a virtual stack if necessary.
|
boolean |
maskBorder(int size)
Make the border have an alpha of zero.
|
boolean |
maskBorder(int left,
int top,
int right,
int bottom)
Make the border have an alpha of zero.
|
void |
mousePressed(MouseEvent me,
Layer la,
int x_p,
int y_p,
double mag) |
void |
paint(Graphics2D g,
Rectangle srcRect,
double magnification,
boolean active,
int channels,
Layer active_layer,
List<Layer> _ignored) |
void |
paintOffscreen(Graphics2D g,
Rectangle srcRect,
double magnification,
boolean active,
int channels,
Layer active_layer,
List<Layer> layers)
Paints waiting for data to load, if necessary.
|
void |
paintSnapshot(Graphics2D g,
Layer layer,
List<Layer> layers,
Rectangle srcRect,
double mag) |
boolean |
paintsWithFalseColor() |
void |
preAppendCoordinateTransform(CoordinateTransform ct)
Pre-append a
CoordinateTransform to the current
CoordinateTransformList . |
void |
prePaint(Graphics2D g,
Rectangle srcRect,
double magnification,
boolean active,
int channels,
Layer active_layer,
List<Layer> _ignored)
Paint first whatever is available, then request that the proper image be loaded and painted.
|
boolean |
remove(boolean check)
Remove only if linked to other Patches or to noone.
|
boolean |
revert()
Revert the ImagePlus to the one stored in original_path, if any; will revert all linked patches if this is part of a stack.
|
String |
set(ij.ImagePlus new_imp)
Set a new ImagePlus for this Patch.
|
protected void |
setAlpha(float alpha,
boolean update) |
boolean |
setAlphaMask(ij.process.ByteProcessor bp)
Must call updateMipMaps() afterwards.
|
void |
setCoordinateTransform(CoordinateTransform ct)
Set a CoordinateTransform to this Patch.
|
void |
setCoordinateTransformSilently(CoordinateTransform ct)
For reconstruction purposes, overwrites the present
CoordinateTransform , if any, with the given one. |
void |
setFilters(IFilter[] fs)
Set an array of @{link
IFilter , which are applied in order to the ImageProcessor
after the preprocessor script is applied but before the rest of TrakEM2 sees the image. |
void |
setMeshResolution(int meshResolution)
Change the resolution of meshes used to render patches transformed by a
CoordinateTransform . |
void |
setMinAndMax(double min,
double max)
The min and max values are stored with the Patch, so that the image can be flushed away but the non-destructive contrast settings preserved.
|
protected boolean |
setNewCoordinateTransform(CoordinateTransform ct)
Writes the
CoordinateTransform t to the trakem2.transforms/ directory, using the unique ct_id
and this Patch 's DBObject.id to generate a file path for it. |
void |
setPreprocessorScriptPath(String path)
After setting a preprocessor script, it is advisable that you call updateMipMaps() immediately.
|
double[] |
toPixelCoordinate(double world_x,
double world_y)
Transfer a world coordinate (in pixels, uncalibrated) to the coordinate space of the original image.
|
static double[] |
toPixelCoordinate(double world_x,
double world_y,
AffineTransform aff,
CoordinateTransform ct,
int meshResolution,
int o_width,
int o_height) |
Future<Boolean> |
updateMipMaps()
Recreate mipmaps and flush away any cached ones.
|
void |
updatePixelProperties(ij.ImagePlus imp)
Update type, original dimensions and min,max from the ImagePlus.
|
adjustProperties, areThereLayerCrossLinks, canSendTo, clone, clone, commonDTDChildren, contains, deselect, destroy, displacePoints, exportDTD, exportSVG, findById, findNearestPoint, findNearestPoint, getAffineTransform, getAffineTransformCopy, getAlpha, getAnnotation, getAreaAt, getBoundingBox, getBoundingBox, getBoundingBox, getBounds, getBounds, getBucketable, getColor, getComposite, getComposite, getCompositeMode, getHeight, getIntersection, getLayer, getLayerIds, getLayerSet, getLayersWithData, getLinked, getLinked, getLinkedBox, getLinkedGroup, getLinkedProperties, getLinkedProperties, getLinkedProperty, getLinkedProperty, getMinimalBoundingBox, getNameId, getPerimeter, getPerimeter, getProperties, getProperty, getProperty, getShortTitle, getTitle, getWidth, getX, getXMLSafeValue, getXMLSafeValue, getY, hasLinkedGroupWithinLayer, hasProperties, intersects, intersects, intersects, inverseTransformPoint, isLinked, isLinked, isLinked, isLocked, isLocked2, isOnlyLinkedTo, isOnlyLinkedTo, isOutOfRepaintingClip, isOutOfRepaintingClip, isVisible, link, link, makeAdjustPropertiesDialog, measure, mouseDragged, mouseReleased, mouseWheelMoved, paintAsBox, preConcatenate, preTransform, processAdjustPropertiesDialog, remove2, removeLinkedProperties, removeLinkedPropertiesFromOrigins, repaint, restXML, rotate, rotate, rotatePoints, scale, scale, scalePoints, setAffineTransform, setAlpha, setAnnotation, setColor, setCompositeMode, setDimensions, setDimensions, setLayer, setLayer, setLinkedProperties, setLinkedProperty, setLocation, setLocked, setProperty, setTitle, setVisible, setVisible, snapTo, softRemove, toString, transform, transformPoint, transformPoint, transformPoints, transformPoints, transformPoints, transformPoints, transformPoints, transformPoints, transformPoints, transformPoints, transformPoints, transformRectangle, translate, translate, unlink, unlink, unlinkAll, updateBucket, updateInDatabase, xmlError, xmlError
addToDatabase, getId, getInfo, getProject, getUniqueIdentifier, removeFromDatabase, updateInDatabase
protected int meshResolution
public static final DirectColorModel DCM
public Patch(Project project, String title, double x, double y, ij.ImagePlus imp)
imp
by calling Loader.addedPatchFrom(String, Patch)
, as in this example:
project.getLoader().addedPatchFrom("/path/to/file.png", thePatch);public Patch(Project project, long id, String title, float width, float height, int o_width, int o_height, int type, boolean locked, double min, double max, AffineTransform at)
public Patch(Project project, String title, float width, float height, int o_width, int o_height, int type, float alpha, Color color, boolean locked, double min, double max, AffineTransform at, String file_path)
file_path
.public int getMeshResolution()
public void setMeshResolution(int meshResolution)
CoordinateTransform
. The method has to update bounding box
offsets introduced by the CoordinateTransform
because the
bounding box has been calculated using the mesh.meshResolution
- public static final Patch createPatch(Project project, String filepath) throws Exception
filepath
with the project's loader.
This method is intended for scripting, to avoid having to create a new Patch
and then call Loader.addedPatchFrom(String, Patch)
, which is easy to forget.Exception
- if the image cannot be loaded from the filepath
, or it's an unsupported type such as a composite image or a hyperstack.public int getOWidth()
public int getOHeight()
public ij.ImagePlus getImagePlus()
public ij.process.ImageProcessor getImageProcessor()
public Future<Boolean> updateMipMaps()
public void updatePixelProperties(ij.ImagePlus imp)
public String set(ij.ImagePlus new_imp)
public void setMinAndMax(double min, double max)
public double getMin()
public double getMax()
public int getType()
public Image createImage(ij.ImagePlus imp)
public Image createImage()
public int getChannelAlphas()
public final Image adjustChannels(Image awt)
public void paintOffscreen(Graphics2D g, Rectangle srcRect, double magnification, boolean active, int channels, Layer active_layer, List<Layer> layers)
Displayable
paintOffscreen
in class Displayable
public void paint(Graphics2D g, Rectangle srcRect, double magnification, boolean active, int channels, Layer active_layer, List<Layer> _ignored)
paint
in interface Paintable
paint
in class Displayable
public void prePaint(Graphics2D g, Rectangle srcRect, double magnification, boolean active, int channels, Layer active_layer, List<Layer> _ignored)
prePaint
in interface Paintable
prePaint
in class Displayable
public boolean isDeletable()
isDeletable
in class Displayable
public boolean remove(boolean check)
remove
in class Displayable
public final boolean isStack()
public PatchStack makePatchStack()
public void exportXML(StringBuilder sb_body, String indent, XMLOptions options)
exportXML
in class Displayable
public static void exportDTD(StringBuilder sb_header, HashSet<String> hs, String indent)
public Displayable clone(Project pr, boolean copy_id)
clone
in class Displayable
public Patch.TransformProperties getTransformPropertiesCopy()
public boolean linkPatches()
linkPatches
in class Displayable
public void paintSnapshot(Graphics2D g, Layer layer, List<Layer> layers, Rectangle srcRect, double mag)
paintSnapshot
in class Displayable
protected static void crosslink(Collection<Displayable> patches, boolean overlapping_only)
public int getPixel(double mag, int x, int y)
public int[] getPixel(double mag, int x, int y, int[] iArray)
public int[] getPixel(int x, int y, double mag)
protected void approximateTransferPixel(int[] pvalue)
public final String getFilePath()
public final String getImageFilePath()
public final String getCurrentPath()
public final void cacheCurrentPath(String path)
public String getOriginalPath()
protected void setAlpha(float alpha, boolean update)
setAlpha
in class Displayable
public void debug()
public boolean revert()
public void setCoordinateTransformSilently(CoordinateTransform ct)
CoordinateTransform
, if any, with the given one.
This method has been repurposed to write the CoordinateTransform
to disk and set a new ct_id
that points to it.public final void setCoordinateTransform(CoordinateTransform ct)
public final void appendCoordinateTransform(CoordinateTransform ct)
CoordinateTransform
to the current
CoordinateTransformList
. If there is no transform yet, it just
sets it. If there is only one transform, it replaces it by a list
containing both, the existing first.public final void preAppendCoordinateTransform(CoordinateTransform ct)
CoordinateTransform
to the current
CoordinateTransformList
. If there is no transform yet, it just
sets it. If there is only one transform, it replaces it by a list
containing both, the new one first.public final Rectangle getCoordinateTransformBoundingBox()
protected static final Rectangle getCoordinateTransformBoundingBox(Patch p, CoordinateTransform ct)
CoordinateTransform
that was already loaded from a file.p
- ct
- public final CoordinateTransform getCoordinateTransform()
CoordinateTransform
that transfers image data to mipmap image data.CoordinateTransform
, or null if none.setCoordinateTransform(CoordinateTransform)
public final CoordinateTransform getFullCoordinateTransform()
CoordinateTransform
that incorporates both the
CoordinateTransform
of this Patch
(if present) and its
AffineTransform
. The returned CoordinateTransform
directly
transfers the Patch
into world coordinates. An image can be rendered
e.g. using TransformMeshMapping
with an
TransformMesh
. Note that you may prefer to use
TransformMesh
which does not perform auto-boxing as
opposed to TransformMesh
in the mpicbg.trakem2 package.public final Patch.PatchImage createCoordinateTransformedImage()
public Patch.PatchImage createTransformedImage()
public final boolean hasAlphaMask()
public long getAlphaMaskId()
public String getAlphaMaskFilePath()
public boolean hasAlphaChannel()
CoordinateTransform
.public boolean setAlphaMask(ij.process.ByteProcessor bp) throws IllegalArgumentException
IllegalArgumentException
public ij.process.ByteProcessor getAlphaMask()
ByteProcessor
representing the alpha mask, if any, over the pixel data.public boolean checkAlphaMaskFile()
alpha_mask_id
== 0
or if the file is found, or false if not found.public boolean paintsWithFalseColor()
public void keyPressed(KeyEvent ke)
keyPressed
in class Displayable
public boolean contains(double x_p, double y_p)
contains
in class Displayable
public void setPreprocessorScriptPath(String path)
public void addAlphaMask(Roi roi, int value)
public void addAlphaMask(Area aw, int value)
public void addAlphaMaskLocal(Area aLocal, int value)
public String getPreprocessorScriptPath()
public boolean isPreprocessed()
public Area getArea()
getArea
in class Displayable
public static ij.process.ImageProcessor makeFlatImage(int type, Layer layer, Rectangle srcRect, double scale, Collection<Patch> patches, Color background)
public static ij.process.ImageProcessor makeFlatImage(int type, Layer layer, Rectangle srcRect, double scale, Collection<Patch> patches, Color background, boolean setMinAndMax)
type
- Any of ImagePlus.GRAY_8, GRAY_16, GRAY_32 or COLOR_RGB.srcRect
- the box in world coordinates to make an image out of.scale
- may be up to 1.0.patches
- The list of patches to paint. The first gets painted first (at the bottom).background
- The color with which to paint the outsides where no image paints into.setMinAndMax
- defines whether the min and max of each Patch is set before pasting the Patch.
For exporting while blending the display ranges (min,max) and respecting alpha masks, see ExportUnsignedShort
.@Deprecated public static final ij.process.ImageProcessor makeFlatGrayImage(List<Patch> patches, Rectangle finalBox, int backgroundValue, double scale)
patches
- finalBox
- backgroundValue
- scale
- public boolean maskBorder(int size)
public boolean maskBorder(int left, int top, int right, int bottom)
protected Area getAreaForBucket(Layer l)
getAreaForBucket
in class Displayable
protected boolean isRoughlyInside(Layer l, Rectangle r)
Displayable
isRoughlyInside
in class Displayable
public boolean intersects(Displayable d, boolean sloppy)
public boolean intersects(Displayable d)
Displayable
intersects
in class Displayable
public void appendFilters(IFilter[] fs)
fs
- The array of IFilter
to use for this Patch.setFilters(IFilter[])
,
getFilters()
public void setFilters(IFilter[] fs)
IFilter
, which are applied in order to the ImageProcessor
after the preprocessor script is applied but before the rest of TrakEM2 sees the image.fs
- The array of IFilter
to use for this Patch. Can be null.appendFilters(IFilter[])
,
getFilters()
public IFilter[] getFilters()
IFilter
of this Patch
.appendFilters(IFilter[])
,
setFilters(IFilter[])
public boolean hasCoordinateTransform()
public long getCoordinateTransformId()
public String getCoordinateTransformFilePath()
CoordinateTransform
, or null if none.public CoordinateTransform fetchCoordinateTransform() throws Exception
CoordinateTransform
from a file whose name is crafted
from the ct_id
and this Patch
's DBObject.id
.CoordinateTransform
of this Patch
, or null if none.Exception
- if the file could not be found or parsed or read.protected boolean setNewCoordinateTransform(CoordinateTransform ct) throws Exception
CoordinateTransform
t
to the trakem2.transforms/ directory, using the unique ct_id
and this Patch
's DBObject.id
to generate a file path for it.Exception
- if the new file could not be written.public boolean checkCoordinateTransformFile()
ct_id
== 0
or if the file is found, or false if not found.public double[] toPixelCoordinate(double world_x, double world_y) throws NoninvertibleTransformException
Patch
space by inverting the AffineTransform
and then, if there is a CoordinateTransform
, that is inverted as well to reach the coordinate space of the original image.world_x
- world_y
- double[]
array with the x,y values.NoninvertibleTransformException
public static final double[] toPixelCoordinate(double world_x, double world_y, AffineTransform aff, CoordinateTransform ct, int meshResolution, int o_width, int o_height) throws NoninvertibleTransformException
world_x
- The X of the world coordinate (in pixels, uncalibrated)world_y
- The Y of the world coordinate (in pixels, uncalibrated)aff
- The AffineTransform
of the Patch
.ct
- The CoordinateTransform
of the Patch
, if any (can be null).meshResolution
- The precision demanded for approximating a transform with a TransformMesh
.o_width
- The width of the image underlying the Patch
.o_height
- The height of the image underlying the Patch
.double[]
array with the x,y values.NoninvertibleTransformException
toPixelCoordinate(double, double)
public AffineTransform getLocalAffine(double wx, double wy)
wx
- wy
- public double getLocalScale(double wx, double wy)
public void mousePressed(MouseEvent me, Layer la, int x_p, int y_p, double mag)
mousePressed
in class Displayable
public boolean clearIntensityMap()
Copyright © 2015–2021 Fiji. All rights reserved.