Java Code Examples for ij.process.ShortProcessor#set()

The following examples show how to use ij.process.ShortProcessor#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeodesicDistanceTransformShort5x5.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
private ShortProcessor initialize(ImageProcessor marker)
{
	// size of image
	sizeX = marker.getWidth();
	sizeY = marker.getHeight();
	
	ShortProcessor distMap = new ShortProcessor(sizeX, sizeY);
	distMap.setValue(0);
	distMap.fill();

	// initialize empty image with either 0 (foreground) or Inf (background)
	for (int y = 0; y < sizeY; y++) 
	{
		for (int x = 0; x < sizeX; x++) 
		{
			int val = marker.get(x, y) & 0x00ff;
			distMap.set(x, y, val == 0 ? Short.MAX_VALUE : 0);
		}
	}

	return distMap;
}
 
Example 2
Source File: GeodesicDistanceTransformShort.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
private ShortProcessor initialize(ImageProcessor marker)
{
	// size of image
	sizeX = marker.getWidth();
	sizeY = marker.getHeight();
	
	ShortProcessor distMap = new ShortProcessor(sizeX, sizeY);
	distMap.setValue(0);
	distMap.fill();

	// initialize empty image with either 0 (foreground) or Inf (background)
	for (int y = 0; y < sizeY; y++) 
	{
		for (int x = 0; x < sizeX; x++) 
		{
			int val = marker.get(x, y) & 0x00ff;
			distMap.set(x, y, val == 0 ? Short.MAX_VALUE : 0);
		}
	}

	return distMap;
}
 
Example 3
Source File: DistanceTransform5x5Short.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
private ShortProcessor initializeResult(ImageProcessor labelImage)
{
	this.fireStatusChanged(new AlgoEvent(this, "Initialization"));

	// size of image
	int sizeX = labelImage.getWidth();
	int sizeY = labelImage.getHeight();

	// create new empty image, and fill it with black
	ShortProcessor distMap = new ShortProcessor(sizeX, sizeY);
	distMap.setValue(0);
	distMap.fill();

	// initialize empty image with either 0 (background) or Inf (foreground)
	for (int y = 0; y < sizeY; y++) 
	{
		for (int x = 0; x < sizeX; x++)
		{
			int label = (int) labelImage.getf(x, y);
			distMap.set(x, y, label == 0 ? 0 : Short.MAX_VALUE);
		}
	}
	
	return distMap;
}
 
Example 4
Source File: DistanceTransform5x5Short.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void normalizeResult(ShortProcessor distMap, ImageProcessor labelImage)
{
	this.fireStatusChanged(new AlgoEvent(this, "Normalization"));
	
	// size of image
	int sizeX = labelImage.getWidth();
	int sizeY = labelImage.getHeight();

	// normalization weight
	int w0 = weights[0];
	
	for (int y = 0; y < sizeY; y++)
	{
		for (int x = 0; x < sizeX; x++)
		{
			if ((int) labelImage.getf(x, y) > 0)
			{
				distMap.set(x, y, distMap.get(x, y) / w0);
			}
		}
	}
}
 
Example 5
Source File: DistanceTransform3x3Short.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
private ShortProcessor initializeResult(ImageProcessor labelImage)
{
	this.fireStatusChanged(new AlgoEvent(this, "Initialization"));

	// size of image
	int sizeX = labelImage.getWidth();
	int sizeY = labelImage.getHeight();

	// create new empty image, and fill it with black
	ShortProcessor distMap = new ShortProcessor(sizeX, sizeY);
	distMap.setValue(0);
	distMap.fill();

	// initialize empty image with either 0 (background) or Inf (foreground)
	for (int y = 0; y < sizeY; y++) 
	{
		for (int x = 0; x < sizeX; x++)
		{
			int label = (int) labelImage.getf(x, y);
			distMap.set(x, y, label == 0 ? 0 : Short.MAX_VALUE);
		}
	}
	
	return distMap;
}
 
Example 6
Source File: DistanceTransform3x3Short.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void normalizeResult(ShortProcessor distMap, ImageProcessor labelImage)
{
	this.fireStatusChanged(new AlgoEvent(this, "Normalization"));
	
	// size of image
	int sizeX = labelImage.getWidth();
	int sizeY = labelImage.getHeight();

	// normalization weight
	int w0 = weights[0];
	
	for (int y = 0; y < sizeY; y++)
	{
		for (int x = 0; x < sizeX; x++)
		{
			if ((int) labelImage.getf(x, y) > 0)
			{
				distMap.set(x, y, distMap.get(x, y) / w0);
			}
		}
	}
}
 
Example 7
Source File: HackLabelEdgesClient.java    From render with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected ImageProcessor loadImageProcessor(final String url,
                                            final int downSampleLevels,
                                            final boolean isMask,
                                            final boolean convertTo16Bit)
        throws IllegalArgumentException {

    final ImageProcessor imageProcessor =
            super.loadImageProcessor(url, downSampleLevels, isMask, convertTo16Bit);

    if (! isMask) {

        final ShortProcessor shortProcessor = (ShortProcessor) imageProcessor;

        final List<TileEdgeAndColor> tileEdgeAndColorList = urlToEdgeAndColorList.get(url);

        if (tileEdgeAndColorList != null) {

            for (final TileEdgeAndColor tileEdgeAndColor : tileEdgeAndColorList) {

                int minX = 0;
                int maxX = shortProcessor.getWidth();
                int minY = 0;
                int maxY = shortProcessor.getHeight();

                switch (tileEdgeAndColor.tileEdge.position) {
                    case TOP:
                        maxY = minY + edgePixelSize;
                        break;
                    case RIGHT:
                        minX = maxX - edgePixelSize;
                        break;
                    case BOTTOM:
                        minY = maxY - edgePixelSize;
                        break;
                    case LEFT:
                        maxX = minX + edgePixelSize;
                        break;
                }

                final short edgeRGB = (short) tileEdgeAndColor.color.getRGB();
                for (int y = minY; y < maxY; y++) {
                    for (int x = minX; x < maxX; x++) {
                        shortProcessor.set(x, y, edgeRGB);
                    }
                }

                if (LOG.isDebugEnabled()) {
                    LOG.debug("loadImageProcessor: set {} {} pixel edge of tile {} to color {}",
                              tileEdgeAndColor.tileEdge.position,
                              edgePixelSize,
                              tileEdgeAndColor.tileEdge.tileId,
                              shortProcessor.get(minX, minY));
                }
            }

        }

    }

    return imageProcessor;
}
 
Example 8
Source File: DistanceTransform5x5Short.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void forwardScan(ShortProcessor distMap, ImageProcessor labelImage) 
{
	this.fireStatusChanged(new AlgoEvent(this, "Forward Scan"));

	// Initialize pairs of offset and weights
	int[] dx = new int[]{-1, +1,  -2, -1,  0, +1, +2,  -1};
	int[] dy = new int[]{-2, -2,  -1, -1, -1, -1, -1,   0};
	short[] dw = new short[] { 
			weights[2], weights[2], 
			weights[2], weights[1], weights[0], weights[1], weights[2], 
			weights[0] };
	
	//  size of image
	int sizeX = labelImage.getWidth();
	int sizeY = labelImage.getHeight();

	// Iterate over pixels
	for (int y = 0; y < sizeY; y++)
	{
		this.fireProgressChanged(this, y, sizeY);
		for (int x = 0; x < sizeX; x++)
		{
			// get current label
			int label = (int) labelImage.getf(x, y);
			
			// do not process background pixels
			if (label == 0)
				continue;
			
			// current distance value
			int currentDist = distMap.get(x, y);
			int newDist = currentDist;
			
			// iterate over neighbors
			for (int i = 0; i < dx.length; i++)
			{
				// compute neighbor coordinates
				int x2 = x + dx[i];
				int y2 = y + dy[i];
				
				// check bounds
				if (x2 < 0 || x2 >= sizeX)
					continue;
				if (y2 < 0 || y2 >= sizeY)
					continue;
				
				if ((int) labelImage.getf(x2, y2) != label)
				{
					// Update with distance to nearest different label
					newDist = Math.min(newDist, dw[i]);
				}
				else
				{
					// Increment distance
					newDist = Math.min(newDist, distMap.get(x2, y2) + dw[i]);
				}
			}
			
			if (newDist < currentDist) 
			{
				distMap.set(x, y, newDist);
			}
		}
	}
	
	this.fireProgressChanged(this, sizeY, sizeY);
}
 
Example 9
Source File: DistanceTransform5x5Short.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void backwardScan(ShortProcessor distMap, ImageProcessor labelImage) 
{
	this.fireStatusChanged(new AlgoEvent(this, "Backward Scan"));

	// Initialize pairs of offset and weights
	int[] dx = new int[]{+1, -1,  +2, +1,  0, -1, -2,  +1};
	int[] dy = new int[]{+2, +2,  +1, +1, +1, +1, +1,   0};
	short[] dw = new short[] { 
			weights[2], weights[2], 
			weights[2], weights[1], weights[0], weights[1], weights[2], 
			weights[0] };
	
	//  size of image
	int sizeX = labelImage.getWidth();
	int sizeY = labelImage.getHeight();

	// Iterate over pixels
	for (int y = sizeY-1; y >= 0; y--)
	{
		this.fireProgressChanged(this, sizeY-1-y, sizeY);
		for (int x = sizeX-1; x >= 0; x--)
		{
			// get current label
			int label = (int) labelImage.getf(x, y);
			
			// do not process background pixels
			if (label == 0)
				continue;
			
			// current distance value
			int currentDist = distMap.get(x, y);
			int newDist = currentDist;
			
			// iterate over neighbors
			for (int i = 0; i < dx.length; i++)
			{
				// compute neighbor coordinates
				int x2 = x + dx[i];
				int y2 = y + dy[i];
				
				// check bounds
				if (x2 < 0 || x2 >= sizeX)
					continue;
				if (y2 < 0 || y2 >= sizeY)
					continue;
				
				if ((int) labelImage.getf(x2, y2) != label)
				{
					// Update with distance to nearest different label
				    newDist = Math.min(newDist, dw[i]);
				}
				else
				{
					// Increment distance
					newDist = Math.min(newDist, distMap.get(x2, y2) + dw[i]);
				}
			}
			
			if (newDist < currentDist) 
			{
				distMap.set(x, y, newDist);
			}
		}
	}
	
	this.fireProgressChanged(this, sizeY, sizeY);
}
 
Example 10
Source File: DistanceTransform3x3Short.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void forwardScan(ShortProcessor distMap, ImageProcessor labelImage) 
{
	this.fireStatusChanged(new AlgoEvent(this, "Forward Scan"));

	int[] dx = new int[]{-1, 0, +1, -1};
	int[] dy = new int[]{-1, -1, -1, 0};
	int[] dw = new int[]{weights[1], weights[0], weights[1], weights[0]};
	
	// size of image
	int sizeX = labelImage.getWidth();
	int sizeY = labelImage.getHeight();

	// Iterate over pixels
	for (int y = 0; y < sizeY; y++)
	{
		this.fireProgressChanged(this, y, sizeY);
		for (int x = 0; x < sizeX; x++)
		{
			// get current label
			int label = (int) labelImage.getf(x, y);
			
			// do not process background pixels
			if (label == 0)
				continue;
			
			// current distance value
			int currentDist = distMap.get(x, y);
			int newDist = currentDist;
			
			// iterate over neighbors
			for (int i = 0; i < dx.length; i++)
			{
				// compute neighbor coordinates
				int x2 = x + dx[i];
				int y2 = y + dy[i];
				
				// check bounds
				if (x2 < 0 || x2 >= sizeX)
					continue;
				if (y2 < 0 || y2 >= sizeY)
					continue;
				
				if ((int) labelImage.getf(x2, y2) != label)
				{
					// Update with distance to nearest different label
				    newDist = Math.min(newDist, dw[i]);
				}
				else
				{
					// Increment distance
					newDist = Math.min(newDist, distMap.get(x2, y2) + dw[i]);
				}
			}
			
			if (newDist < currentDist) 
			{
				distMap.set(x, y, newDist);
			}
		}
	}
	
	this.fireProgressChanged(this, sizeY, sizeY);
}
 
Example 11
Source File: DistanceTransform3x3Short.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void backwardScan(ShortProcessor distMap, ImageProcessor labelImage) 
{
	this.fireStatusChanged(new AlgoEvent(this, "Backward Scan"));

	int[] dx = new int[]{+1, 0, -1, +1};
	int[] dy = new int[]{+1, +1, +1, 0};
	int[] dw = new int[]{weights[1], weights[0], weights[1], weights[0]};

	// size of image
	int sizeX = labelImage.getWidth();
	int sizeY = labelImage.getHeight();

	// Iterate over pixels
	for (int y = sizeY-1; y >= 0; y--)
	{
		this.fireProgressChanged(this, sizeY-1-y, sizeY);
		for (int x = sizeX-1; x >= 0; x--)
		{
			// get current label
			int label = (int) labelImage.getf(x, y);
			
			// do not process background pixels
			if (label == 0)
				continue;
			
			// current distance value
			int currentDist = distMap.get(x, y);
			int newDist = currentDist;
			
			// iterate over neighbors
			for (int i = 0; i < dx.length; i++)
			{
				// compute neighbor coordinates
				int x2 = x + dx[i];
				int y2 = y + dy[i];
				
				// check bounds
				if (x2 < 0 || x2 >= sizeX)
					continue;
				if (y2 < 0 || y2 >= sizeY)
					continue;
				
				if ((int) labelImage.getf(x2, y2) != label)
				{
					// Update with distance to nearest different label
				    newDist = Math.min(newDist, dw[i]);
				}
				else
				{
					// Increment distance
					newDist = Math.min(newDist, distMap.get(x2, y2) + dw[i]);
				}
			}
			
			if (newDist < currentDist) 
			{
				distMap.set(x, y, newDist);
			}
		}
	}
	
	this.fireProgressChanged(this, sizeY, sizeY);
}