Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

Commit 2a77257b authored by lafabregue's avatar lafabregue
Browse files

allow channel index modification for rgb color

parent 8ca035a4
......@@ -769,9 +769,9 @@ public class ImageSampler extends Sampler {
private void setBoundries(int start, int end) {
for(StreamedImageReaderWrapper w : getReaders()) {
if (geoTranslateVectors != null) {
w.setBoundriesWithNewRef(start, end, imageWidth, imageHeight);
w.setLinearBoundriesWithNewRef(start, end, imageWidth, imageHeight);
} else {
w.setBoundries(start, end);
w.setLinearBoundries(start, end);
}
}
}
......
......@@ -7,6 +7,7 @@ import java.nio.ByteOrder;
import java.util.Arrays;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Vector;
import jcl.utils.MemoryFlush;
import jcl.utils.exceptions.MethodNotImplementedException;
......@@ -80,15 +81,21 @@ public class StreamedImageReaderWrapper implements Iterable<double[]>, MemoryFlu
/** Maximal RAM available for this current instance */
private long maxRAM = 0;
/** X coordinate of the start boundary */
private int startX = -1;
/** Y coordinate of the start boundary */
private int startY = 0;
/** X coordinate of the end boundary */
private int endX = -1;
/** Y coordinate of the end boundary */
private int endY = -1;
/** extrema of the pixels values,
* the first is the minimum and the second the maximum */
private double[] extrema = null;
private double[][] extrema = null;
/** Indicates the order of dimension in the image
* If true pixels are ordered in this fashion :
......@@ -136,6 +143,8 @@ public class StreamedImageReaderWrapper implements Iterable<double[]>, MemoryFlu
this.reader = new ImageReader();
try {
setImage(wrapper.reader.getCurrentFile());
this.extrema = wrapper.extrema;
setMaxRAM(wrapper.maxRAM);
} catch (FormatException | IOException e) {
e.printStackTrace();
}
......@@ -202,6 +211,7 @@ public class StreamedImageReaderWrapper implements Iterable<double[]>, MemoryFlu
* The X coordinate of the pixel
* @param y
* The Y coordinate of the pixel
* @return the value of the pixel at coordinates x,y
*
* @throws IOException
* If there is a problem reading the file
......@@ -231,6 +241,7 @@ public class StreamedImageReaderWrapper implements Iterable<double[]>, MemoryFlu
}
for(int c = 0 ; c < channelCount ; c++) {
// try {
switch (pixelType) {
case FormatTools.BIT:
result[c] = ByteBuffer.wrap(Arrays.copyOfRange(tile, index+gap*c,
......@@ -272,6 +283,11 @@ public class StreamedImageReaderWrapper implements Iterable<double[]>, MemoryFlu
result[c] = 0;
}
// } catch (ArrayIndexOutOfBoundsException e) {
// e.printStackTrace();
// System.out.println("channel : "+c+" index : "+index+" gap : "+gap+" requested pixel : "+x+","+y+
// " tile : "+tileX+","+tileY+" - "+currentTileWidth+","+currentTileHeight);
// }
}
......@@ -324,21 +340,35 @@ public class StreamedImageReaderWrapper implements Iterable<double[]>, MemoryFlu
* @throws FormatException
* If there is a problem parsing the image's metadata
*/
private void loadTile(int x, int y) throws FormatException, IOException {
public void loadTile(int x, int y) throws FormatException, IOException {
tileX = x - x % tileWidth;
tileY = y - y % tileHeight;
if(tileY < startY) {
if (tileY < startY) {
tileY = startY;
}
if (tileX < startX) {
tileX = startX;
}
currentTileHeight = tileHeight;
if (currentTileHeight+tileY > endY)
currentTileHeight = endY - tileY;
if (endY > 0) {
if (currentTileHeight+tileY > endY)
currentTileHeight = endY - tileY;
} else {
if (currentTileHeight+tileY > imageHeight)
currentTileHeight = imageHeight - tileY;
}
currentTileWidth = tileWidth;
if (currentTileWidth+tileX > imageWidth)
currentTileWidth = imageWidth - tileX;
if (endX > -1) {
if (currentTileWidth+tileX > endX)
currentTileWidth = endX - tileX;
} else {
if (currentTileWidth+tileX > imageWidth)
currentTileWidth = imageWidth - tileX;
}
tile = reader.openBytes(0, tileX, tileY, currentTileWidth, currentTileHeight);
channelGap = tile.length / channelCount;
System.out.println("Tile of "+currentTileWidth+"x"+currentTileHeight+" - "+tileX+","+tileY+" for image of "+imageWidth+"x"+imageHeight);
......@@ -493,8 +523,6 @@ public class StreamedImageReaderWrapper implements Iterable<double[]>, MemoryFlu
* <p>
* Indicates to the wrapper that only a part of the image will be read.
* This allow the reader to just load the necessary pixel in memory.
*
* Note that it is not in a tile fashion, but in a linear one
* <p>
*
* @param startX
......@@ -507,63 +535,92 @@ public class StreamedImageReaderWrapper implements Iterable<double[]>, MemoryFlu
* Y coordinate of the last pixel in the set
*/
public void setBoundries(int startX, int startY, int endX, int endY) {
this.startX = startX;
this.endX = endX;
this.startY = startY;
this.endY = endY;
}
/**
* <p>
* Indicates to the wrapper that only a part of the image will be read.
* This allow the reader to just load the necessary pixel in memory.
*
* Note that it is not in a tile fashion, but in a linear one,
* so X coordinates are not considered
* <p>
*
* @param startX
* X coordinate of the first pixel in the set
* @param startY
* Y coordinate of the first pixel in the set
* @param endX
* X coordinate of the last pixel in the set
* @param endY
* Y coordinate of the last pixel in the set
*/
public void setLinearBoundries(int startX, int startY, int endX, int endY) {
this.startX = -1;
this.endX = -1;
this.startY = startY - (startY % optimaleTileHeight);
this.endY = endY;
}
/**
* Return the smallest pixel value in this image
* Return the smallest values per channels in this image
*
* @return the minimum
*/
public double getMinValue() {
public double[] getMinValues() {
return getExtrema()[0];
}
/**
* Return the bigger pixel value in this image
* Return the bigger values per channels in this image
*
* @return the maximum
*/
public double getMaxValue() {
public double[] getMaxValues() {
return getExtrema()[1];
}
private double[] getExtrema() {
private double[][] getExtrema() {
if(extrema == null) {
extrema = new double[2];
Iterator<double[]> iter = iterator();
// init min and max
double[] pixel0 = iter.next();
extrema[0] = 0;
for(double d : pixel0) {
extrema[0] += d;
extrema = new double[2][pixel0.length];
for(int i = 0 ; i < pixel0.length ; i++) {
extrema[0][i] += pixel0[i];
extrema[1][i] += pixel0[i];
}
extrema[1] = extrema[0];
// get through the image
while(iter.hasNext()) {
double value = 0;
double[] pixel = iter.next();
for(double d : pixel) {
value += d;
for(int i = 0; i < pixel.length ; i++) {
if (pixel[i] < extrema[0][i])
extrema[0][i] = pixel[i];
if (pixel[i] > extrema[1][i])
extrema[1][i] = pixel[i];
}
if (value < extrema[0])
extrema[0] = value;
if (value > extrema[1])
extrema[1] = value;
}
}
return extrema;
}
private double[][] getExtremaThreaded() {
if(extrema == null) {
// TODO
}
return extrema;
}
/**
* <p>
* Indicates to the wrapper that only a part of the image will be read.
* This allow the reader to just load the necessary pixel in memory.
*
* Note that it is not in a tile fashion, but in a linear one
* <p>
*
* @param start
......@@ -575,14 +632,30 @@ public class StreamedImageReaderWrapper implements Iterable<double[]>, MemoryFlu
setBoundries(0, Math.floorDiv(start,imageWidth), 0, (int) Math.ceil((double)end/imageWidth));
}
/**
* <p>
* Indicates to the wrapper that only a part of the image will be read.
* This allow the reader to just load the necessary pixel in memory.
*
* Note that it is not in a tile fashion, but in a linear one,
* so X coordinates are not considered
* <p>
*
* @param start
* The first pixel in the set
* @param end
* The last pixel in the set
*/
public void setLinearBoundries(int start, int end) {
setLinearBoundries(0, Math.floorDiv(start,imageWidth), 0, (int) Math.ceil((double)end/imageWidth));
}
/**
* <p>
* Indicates to the wrapper that only a part of the image will be read.
* This allow the reader to just load the necessary pixel in memory.
* It also specify another referential to compute the coordinates that
* is not the image width and height
*
* Note that it is not in a tile fashion, but in a linear one
* <p>
*
* @param start
......@@ -599,6 +672,31 @@ public class StreamedImageReaderWrapper implements Iterable<double[]>, MemoryFlu
setBoundries(0, Math.floorDiv(start,width), 0, (int) Math.ceil((double)end/width));
}
/**
* <p>
* Indicates to the wrapper that only a part of the image will be read.
* This allow the reader to just load the necessary pixel in memory.
* It also specify another referential to compute the coordinates that
* is not the image width and height
*
* Note that it is not in a tile fashion, but in a linear one,
* so X coordinates are not considered
* <p>
*
* @param start
* The first pixel in the set
* @param end
* The last pixel in the set
* @param width
* Width of the new referential
* @param height
* Height of the new referential
*
*/
public void setLinearBoundriesWithNewRef(int start, int end, int width, int height) {
setLinearBoundries(0, Math.floorDiv(start,width), 0, (int) Math.ceil((double)end/width));
}
@Override
public Object clone() {
return new StreamedImageReaderWrapper(this);
......@@ -681,5 +779,30 @@ public class StreamedImageReaderWrapper implements Iterable<double[]>, MemoryFlu
throw new UnsupportedOperationException();
}
}
// public static void main(String[] args) {
//
// String path = "/home/baptiste/Data/malaoui/evi_2013_2014.tif";
// StreamedImageReaderWrapper reader = new StreamedImageReaderWrapper(path);
//
// long allocatedMemory = (Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory());
// long presumableFreeMemory = Runtime.getRuntime().maxMemory() - allocatedMemory;
// // we just tack the 2/3rd of the memory available;
// presumableFreeMemory *= 0.05;
//
// long memoryPerReader = presumableFreeMemory ;
// try {
// reader.setMaxRAM(memoryPerReader);
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// long startT = System.nanoTime();
// System.out.println("start at "+startT);
// double[][] extrema = reader.getExtrema();
// long endT = System.nanoTime();
// System.out.println("endat "+ endT + " total of "+ (endT - startT)/1000000l +"ms");
// System.out.println("extrema : "+Arrays.deepToString(extrema));
// }
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment