Commit 8da4376c authored by lafabregue's avatar lafabregue

Merge branch 'jclFix'

parents f8c22cfc 0a2d9516
......@@ -441,7 +441,7 @@ public class SimpleData extends Data {
return data;
}
private List<DataObject> getDataObjects(final Mask mask) {
public List<DataObject> getDataObjects(final Mask mask) {
if (mask.getOverallCarinality() < getNbObjects()) {
throw new IndexOutOfBoundsException("The nnumber of unmasked pixels"
+ " is lower than the expeted sample size");
......
......@@ -133,4 +133,18 @@ public class FilterEntropy extends Filter {
return rank;
}
@Override
public void setStatus(String status)
{
// TODO Auto-generated method stub
}
@Override
public String getStatus()
{
// TODO Auto-generated method stub
return null;
}
}
......@@ -75,4 +75,18 @@ public class FilterNormalization extends Filter {
}
return (sumDist / nbDist);
}
@Override
public void setStatus(String status)
{
// TODO Auto-generated method stub
}
@Override
public String getStatus()
{
// TODO Auto-generated method stub
return null;
}
}
......@@ -58,6 +58,12 @@ public class ImageSampler extends Sampler {
private int[] mandatoriesIndexes = null;
private List<Mask> maskSequence = null;
private double progress = 0;
private double progressM = 100;
private String status = null;
/**
* Constructor from a sequence of images
......@@ -68,18 +74,18 @@ public class ImageSampler extends Sampler {
* if the images don't have the same dimensions
*/
public ImageSampler(final Vector<String> imagesPaths) throws FormatException {
readers = new Vector<StreamedImageReaderWrapper>();
readers.add(new StreamedImageReaderWrapper(imagesPaths.get(0)));
imageHeight = readers.get(0).getImageHeight();
imageWidth = readers.get(0).getImageWidth();
setReaders(new Vector<StreamedImageReaderWrapper>());
getReaders().add(new StreamedImageReaderWrapper(imagesPaths.get(0)));
imageHeight = getReaders().get(0).getImageHeight();
imageWidth = getReaders().get(0).getImageWidth();
dataSize = imageHeight * imageWidth;
dataUnmaskedSize = dataSize;
if(imagesPaths.size() > 1) {
for(int i = 1; i < imagesPaths.size() ; i++) {
readers.add(new StreamedImageReaderWrapper(imagesPaths.get(i)));
if (imageHeight != readers.get(i).getImageHeight() ||
imageWidth != readers.get(i).getImageWidth()) {
getReaders().add(new StreamedImageReaderWrapper(imagesPaths.get(i)));
if (imageHeight != getReaders().get(i).getImageHeight() ||
imageWidth != getReaders().get(i).getImageWidth()) {
throw new FormatException("The images feed in the ImageSampler"
+ " should all have the same dimensions");
}
......@@ -115,11 +121,11 @@ public class ImageSampler extends Sampler {
*/
public ImageSampler(final Vector<String> imagesPaths, Vector<double[]> geoTranslateVectors,
int startX, int startY, int endX, int endY) throws FormatException {
this.readers = new Vector<StreamedImageReaderWrapper>();
this.readers.add(new StreamedImageReaderWrapper(imagesPaths.get(0)));
this.setReaders(new Vector<StreamedImageReaderWrapper>());
this.getReaders().add(new StreamedImageReaderWrapper(imagesPaths.get(0)));
// test id the boundries match at least the first image
if (endY >= this.readers.get(0).getImageHeight() ||
endX >= this.readers.get(0).getImageWidth()) {
if (endY >= this.getReaders().get(0).getImageHeight() ||
endX >= this.getReaders().get(0).getImageWidth()) {
throw new FormatException("The images feed in the ImageSampler should at "
+ "least contain the rectangle from the star and end coordinates.");
}
......@@ -134,7 +140,7 @@ public class ImageSampler extends Sampler {
if(imagesPaths.size() > 1) {
for(int i = 1; i < imagesPaths.size() ; i++) {
readers.add(new StreamedImageReaderWrapper(imagesPaths.get(i)));
getReaders().add(new StreamedImageReaderWrapper(imagesPaths.get(i)));
}
}
......@@ -152,10 +158,10 @@ public class ImageSampler extends Sampler {
* if the images don't have the same dimensions
*/
public ImageSampler(final String imagesPaths) {
readers = new Vector<StreamedImageReaderWrapper>();
readers.add(new StreamedImageReaderWrapper(imagesPaths));
imageHeight = readers.get(0).getImageHeight();
imageWidth = readers.get(0).getImageWidth();
setReaders(new Vector<StreamedImageReaderWrapper>());
getReaders().add(new StreamedImageReaderWrapper(imagesPaths));
imageHeight = getReaders().get(0).getImageHeight();
imageWidth = getReaders().get(0).getImageWidth();
dataSize = imageHeight * imageWidth;
dataUnmaskedSize = dataSize;
......@@ -172,9 +178,9 @@ public class ImageSampler extends Sampler {
* if the images don't have the same dimensions
*/
public ImageSampler(ImageSampler sampler) {
readers = new Vector<StreamedImageReaderWrapper>();
for(StreamedImageReaderWrapper r : sampler.readers) {
readers.add((StreamedImageReaderWrapper) r.clone());
setReaders(new Vector<StreamedImageReaderWrapper>());
for(StreamedImageReaderWrapper r : sampler.getReaders()) {
getReaders().add((StreamedImageReaderWrapper) r.clone());
}
imageHeight = sampler.imageHeight;
imageWidth = sampler.imageWidth;
......@@ -194,6 +200,7 @@ public class ImageSampler extends Sampler {
@Override
public List<DataObject> getDataObjects() {
// if a mask is applied we use it
resetProgress();
if (mask != null) {
return getDataObjects(mask);
}
......@@ -203,7 +210,7 @@ public class ImageSampler extends Sampler {
+ " is bigger than the expeted sample size");
}
updateRAMAvailable(false);
if (readers.size() > 1) {
if (getReaders().size() > 1) {
return getDataFromImagesSequence();
} else {
return getDataFromOneImage();
......@@ -217,11 +224,11 @@ public class ImageSampler extends Sampler {
throw new IndexOutOfBoundsException("The number of mandatory pixels"
+ " is bigger than the expeted sample size");
}
if (mask.getCarinality() < sizeByCount) {
if (mask.getCarinality() < sizeByCount) {
throw new IndexOutOfBoundsException("The number of unmasked pixels"
+ " is lower than the expeted sample size");
}
if (readers.size() > 1) {
if (getReaders().size() > 1) {
return getDataFromImagesSequence(mask, mandatoryPixelCount);
} else {
return getDataFromOneImage(mask, mandatoryPixelCount);
......@@ -248,10 +255,11 @@ public class ImageSampler extends Sampler {
*/
private List<DataObject> getDataFromOneImage() {
List<DataObject> result = new ArrayList<DataObject>(sizeByCount);
setStatus("loading sampler...");
int index = 0;
int x = 0;
int y = 0;
int channelCount = readers.get(0).getChannelCount();
int channelCount = getReaders().get(0).getChannelCount();
switch (getSamplingMethod()) {
case Sampler.RANDOM_METHOD_TYPE :
selectedIndexes = RandomizeTools.getReservoirSamplingIndex(getDataSize(), sizeByCount);
......@@ -270,22 +278,31 @@ public class ImageSampler extends Sampler {
}
break;
}
resetProgress();
int jalon = sizeByCount/10;
for(int i = 0; i < sizeByCount ; i++) {
index = getIndex(i);
x = (index) % imageWidth;
y = (index) / imageWidth;
result.add(new DataObject(channelCount));
try {
double [] pixel = readers.get(0).getPixel(x, y);
for(int c = 0 ; c < readers.get(0).getChannelCount() ; c++) {
double [] pixel = getReaders().get(0).getPixel(x, y);
for(int c = 0 ; c < getReaders().get(0).getChannelCount() ; c++) {
result.get(i).setAttribute(c, new AttributeNumerical(pixel[c]));
}
} catch (FormatException | IOException e) {
e.printStackTrace();
}
if(i == jalon)
{
jalon+=sizeByCount/10;
incProgress();
}
}
endProgress();
return result;
}
......@@ -302,9 +319,10 @@ public class ImageSampler extends Sampler {
*/
private List<DataObject> getDataFromOneImage(final Mask mask, int mandatoryPixelCount) {
List<DataObject> result = new ArrayList<DataObject>(sizeByCount);
setStatus("loading sampler...");
int x = 0;
int y = 0;
int channelCount = readers.get(0).getChannelCount();
int channelCount = getReaders().get(0).getChannelCount();
double tmpOffset = (double) mask.getCarinality() / sizeByCount;
double iterPos = 0.0;
int index = 0;
......@@ -328,6 +346,9 @@ public class ImageSampler extends Sampler {
iter = mask.getIncludedIndexes();
break;
}
resetProgress();
int jalon = sizeByCount/10;
for(int i = 0; i < sizeByCount ; i++) {
if (getSamplingMethod() == Sampler.INTERVAL_METHOD_TYPE) {
......@@ -348,16 +369,21 @@ public class ImageSampler extends Sampler {
result.add(new DataObject(channelCount));
try {
double [] pixel = readers.get(0).getPixel(x, y);
for(int c = 0 ; c < readers.get(0).getChannelCount() ; c++) {
double [] pixel = getReaders().get(0).getPixel(x, y);
for(int c = 0 ; c < getReaders().get(0).getChannelCount() ; c++) {
result.get(i).setAttribute(c, new AttributeNumerical(pixel[c]));
}
} catch (FormatException | IOException e) {
e.printStackTrace();
}
}
if(i == jalon)
{
jalon+=sizeByCount/10;
incProgress();
}
}
endProgress();
return result;
}
......@@ -367,10 +393,14 @@ public class ImageSampler extends Sampler {
*/
private List<DataObject> getDataFromImagesSequence() {
List<DataObject> result = new ArrayList<DataObject>(sizeByCount);
setStatus("loading sampler...");
resetProgress();
int jalon = sizeByCount/10;
int index = 0;
int x = 0;
int y = 0;
int channelCount = readers.get(0).getChannelCount();
int channelCount = getReaders().get(0).getChannelCount();
switch (getSamplingMethod()) {
case Sampler.RANDOM_METHOD_TYPE :
selectedIndexes = RandomizeTools.getReservoirSamplingIndex(getDataSize(), sizeByCount);
......@@ -390,7 +420,8 @@ public class ImageSampler extends Sampler {
break;
}
for(int i = 0; i < sizeByCount ; i++) {
for(int i = 0; i < sizeByCount ; i++)
{
index = getIndex(i);
x = getStartX() + index % imageWidth;
y = getStartY() + index / imageWidth;
......@@ -403,16 +434,16 @@ public class ImageSampler extends Sampler {
double geoX = geoTranslateVectors.get(0)[0] + ((double)x)*geoTranslateVectors.get(0)[2];
double geoY = geoTranslateVectors.get(0)[1] + ((double)y)*geoTranslateVectors.get(0)[3];
for(int j= 0 ; j < readers.size() ; j++) {
for(int j= 0 ; j < getReaders().size() ; j++) {
// reverse compute the image coordinate
int imgX = (int) ((geoX - geoTranslateVectors.get(j)[0]) /geoTranslateVectors.get(j)[2]);
int imgY = (int) ((geoY - geoTranslateVectors.get(j)[1]) /geoTranslateVectors.get(j)[3]);
// check if the pixel is not partially masked by a sequence mask
if (maskSequence == null || maskSequence.get(j) == null ||
!maskSequence.get(j).isMasked(imgX+imgY*readers.get(j).getImageWidth())) {
!maskSequence.get(j).isMasked(imgX+imgY*getReaders().get(j).getImageWidth())) {
values.add(readers.get(j).getPixel(imgX, imgY));
values.add(getReaders().get(j).getPixel(imgX, imgY));
}
}
if (values.size() > 0) {
......@@ -426,10 +457,10 @@ public class ImageSampler extends Sampler {
result.remove(result.size()-1);
}
} else {
for(int j= 0 ; j < readers.size() ; j++) {
for(int j= 0 ; j < getReaders().size() ; j++) {
if (maskSequence == null || maskSequence.get(j) == null ||
!maskSequence.get(j).isMasked(x+y*readers.get(j).getImageWidth())) {
values.add(readers.get(j).getPixel(x, y));
!maskSequence.get(j).isMasked(x+y*getReaders().get(j).getImageWidth())) {
values.add(getReaders().get(j).getPixel(x, y));
}
}
if (values.size() > 0) {
......@@ -446,10 +477,17 @@ public class ImageSampler extends Sampler {
} catch (FormatException | IOException e) {
e.printStackTrace();
}
if(i == jalon)
{
jalon+=sizeByCount/10;
incProgress();
}
}
// we need to update in case of elements completely masked by masSequence
sizeByCount = result.size();
updatePercentage();
endProgress();
return result;
}
......@@ -467,9 +505,10 @@ public class ImageSampler extends Sampler {
*/
private List<DataObject> getDataFromImagesSequence(final Mask mask, int mandatoryPixelCount) {
List<DataObject> result = new ArrayList<DataObject>(sizeByCount);
setStatus("loading sampler...");
int x = 0;
int y = 0;
int channelCount = readers.get(0).getChannelCount();
int channelCount = getReaders().get(0).getChannelCount();
double tmpOffset = mask.getCarinality() / sizeByCount;
double iterPos = 0.0;
int index = 0;
......@@ -514,6 +553,10 @@ public class ImageSampler extends Sampler {
y = getStartY() + ((int) index) / readers.get(0).getImageWidth();
result.add(new DataObject(1));
resetProgress();
int jalon = sizeByCount/10;
List<double[]> values = new ArrayList<double[]>();
try {
if (geoTranslateVectors != null) {
......@@ -521,16 +564,16 @@ public class ImageSampler extends Sampler {
double geoX = geoTranslateVectors.get(0)[0] + ((double)x)*geoTranslateVectors.get(0)[2];
double geoY = geoTranslateVectors.get(0)[1] + ((double)y)*geoTranslateVectors.get(0)[3];
for(int j= 0 ; j < readers.size() ; j++) {
for(int j= 0 ; j < getReaders().size() ; j++) {
// reverse compute the image coordinate
int imgX = (int) ((geoX - geoTranslateVectors.get(j)[0]) /geoTranslateVectors.get(j)[2]);
int imgY = (int) ((geoY - geoTranslateVectors.get(j)[1]) /geoTranslateVectors.get(j)[3]);
// check if the pixel is not partially masked by a sequence mask
if (maskSequence == null || maskSequence.get(j) == null ||
!maskSequence.get(j).isMasked(imgX+imgY*readers.get(j).getImageWidth())) {
!maskSequence.get(j).isMasked(imgX+imgY*getReaders().get(j).getImageWidth())) {
values.add(readers.get(j).getPixel(imgX, imgY));
values.add(getReaders().get(j).getPixel(imgX, imgY));
}
}
if (values.size() > 0) {
......@@ -544,10 +587,10 @@ public class ImageSampler extends Sampler {
values.remove(result.size()-1);
}
} else {
for(int j= 0 ; j < readers.size() ; j++) {
for(int j= 0 ; j < getReaders().size() ; j++) {
if (maskSequence == null || maskSequence.get(j) == null ||
!maskSequence.get(j).isMasked(x+y*readers.get(j).getImageWidth())) {
values.add(readers.get(j).getPixel(x, y));
!maskSequence.get(j).isMasked(x+y*getReaders().get(j).getImageWidth())) {
values.add(getReaders().get(j).getPixel(x, y));
}
}
if (values.size() > 0) {
......@@ -564,6 +607,12 @@ public class ImageSampler extends Sampler {
} catch (FormatException | IOException e) {
e.printStackTrace();
}
if(i == jalon)
{
jalon+=sizeByCount/10;
incProgress();
}
}
// we need to update in case of elements completely masked by masSequence
sizeByCount = result.size();
......@@ -581,16 +630,17 @@ public class ImageSampler extends Sampler {
* @return the elment
*/
private DataObject getDataObjectFromOneImage(int index) {
setStatus("loading sampler...");
int x = 0;
int y = 0;
int channelCount = readers.get(0).getChannelCount();
int channelCount = getReaders().get(0).getChannelCount();
DataObject result = new DataObject(channelCount);
x = ((int) index) % readers.get(0).getImageWidth();
y = ((int) index) / readers.get(0).getImageWidth();
try {
double [] pixel = readers.get(0).getPixel(x, y);
for(int c = 0 ; c < readers.get(0).getChannelCount() ; c++) {
double [] pixel = getReaders().get(0).getPixel(x, y);
for(int c = 0 ; c < getReaders().get(0).getChannelCount() ; c++) {
result.setAttribute(c, new AttributeNumerical(pixel[c]));
}
} catch (FormatException | IOException e) {
......@@ -610,10 +660,11 @@ public class ImageSampler extends Sampler {
* @return the elment
*/
private DataObject getDataObjectFromImagesSequence(int index) {
setStatus("loading sampler...");
DataObject result = new DataObject(1);
int x = 0;
int y = 0;
int channelCount = readers.get(0).getChannelCount();
int channelCount = getReaders().get(0).getChannelCount();
x = ((int) index) % readers.get(0).getImageWidth();
y = ((int) index) / readers.get(0).getImageWidth();
......@@ -628,21 +679,21 @@ public class ImageSampler extends Sampler {
double geoX = geoTranslateVectors.get(0)[0] + ((double)x)*geoTranslateVectors.get(0)[2];
double geoY = geoTranslateVectors.get(0)[1] + ((double)y)*geoTranslateVectors.get(0)[3];
double[][] buffer = new double[readers.size()][channelCount];
for(int j= 0 ; j < readers.size() ; j++) {
double[][] buffer = new double[getReaders().size()][channelCount];
for(int j= 0 ; j < getReaders().size() ; j++) {
// reverse compute the image coordinate
int imgX = (int) ((geoX - geoTranslateVectors.get(j)[0]) /geoTranslateVectors.get(j)[2]);
int imgY = (int) ((geoY - geoTranslateVectors.get(j)[1]) /geoTranslateVectors.get(j)[3]);;
buffer[j] = readers.get(j).getPixel(imgX, imgY);
buffer[j] = getReaders().get(j).getPixel(imgX, imgY);
}
result.setAttribute(
0,
new AttributeMultiDimSequence(Arrays.copyOf(
buffer, buffer.length)));
} else {
double[][] buffer = new double[readers.size()][channelCount];
for(int j= 0 ; j < readers.size() ; j++) {
buffer[j] = readers.get(j).getPixel(x, y);
double[][] buffer = new double[getReaders().size()][channelCount];
for(int j= 0 ; j < getReaders().size() ; j++) {
buffer[j] = getReaders().get(j).getPixel(x, y);
}
result.setAttribute(
0,
......@@ -692,8 +743,8 @@ public class ImageSampler extends Sampler {
// we just tack the 2/3rd of the memory available;
presumableFreeMemory *= 0.05;
long memoryPerReader = presumableFreeMemory / readers.size();
for(StreamedImageReaderWrapper r : readers) {
long memoryPerReader = presumableFreeMemory / getReaders().size();
for(StreamedImageReaderWrapper r : getReaders()) {
try {
if (toMax) {
r.setMaxRAM(memoryPerReader);
......@@ -716,7 +767,7 @@ public class ImageSampler extends Sampler {
* The last pixel in the set
*/
private void setBoundries(int start, int end) {
for(StreamedImageReaderWrapper w : readers) {
for(StreamedImageReaderWrapper w : getReaders()) {
if (geoTranslateVectors != null) {
w.setBoundriesWithNewRef(start, end, imageWidth, imageHeight);
} else {
......@@ -752,7 +803,7 @@ public class ImageSampler extends Sampler {
public Iterator<DataObject> getWholeData() {
updateRAMAvailable(true);
if (readers.size() > 1) {
if (getReaders().size() > 1) {
if (geoTranslateVectors != null) {
return new GeoTranslatedImageSequenceStreamedIterator((ImageSampler) this.clone());
} else {
......@@ -772,7 +823,7 @@ public class ImageSampler extends Sampler {
ImageSampler sampler = (ImageSampler) this.clone();
sampler.setBoundries(start, end);
if (readers.size() > 1) {
if (getReaders().size() > 1) {
if (geoTranslateVectors != null) {
return new GeoTranslatedImageSequenceStreamedIterator(sampler, start, end);
} else {
......@@ -797,7 +848,7 @@ public class ImageSampler extends Sampler {
@Override
public DataObject getWholeDataDataObject(int index) {
if (readers.size() > 1) {
if (getReaders().size() > 1) {
return getDataObjectFromImagesSequence(index);
} else {
return getDataObjectFromOneImage(index);
......@@ -811,7 +862,7 @@ public class ImageSampler extends Sampler {
@Override
public void flushMemory() throws MethodNotImplementedException {
for(StreamedImageReaderWrapper r : readers) {
for(StreamedImageReaderWrapper r : getReaders()) {
r.flushMemory();
}
......@@ -960,7 +1011,7 @@ public class ImageSampler extends Sampler {
this.endY = sampler.imageHeight;
this.endX = sampler.imageWidth;
this.imageWidth = sampler.imageWidth;
this.reader = sampler.readers.get(0);
this.reader = sampler.getReaders().get(0);
}
......@@ -975,7 +1026,7 @@ public class ImageSampler extends Sampler {
this.endY = end / sampler.imageWidth;
}
this.imageWidth = sampler.imageWidth;
this.reader = sampler.readers.get(0);
this.reader = sampler.getReaders().get(0);
}
public boolean hasNext() {
......@@ -1032,8 +1083,8 @@ public class ImageSampler extends Sampler {
this.endY = sampler.imageHeight;
this.endX = sampler.imageWidth;
this.imageWidth = sampler.imageWidth;
this.readers = sampler.readers;
this.channelCount = sampler.readers.get(0).getChannelCount();
this.readers = sampler.getReaders();
this.channelCount = sampler.getReaders().get(0).getChannelCount();
}
......@@ -1048,8 +1099,8 @@ public class ImageSampler extends Sampler {
this.endY = end / sampler.imageWidth;
}
this.imageWidth = sampler.imageWidth;
this.readers = sampler.readers;
this.channelCount = sampler.readers.get(0).getChannelCount();
this.readers = sampler.getReaders();
this.channelCount = sampler.getReaders().get(0).getChannelCount();
}
public boolean hasNext() {
......@@ -1116,8 +1167,8 @@ public class ImageSampler extends Sampler {
this.bStartX = sampler.getStartX();
this.bStartY = sampler.getStartY();
this.imageWidth = sampler.imageWidth;
this.readers = sampler.readers;
this.channelCount = sampler.readers.get(0).getChannelCount();
this.readers = sampler.getReaders();
this.channelCount = sampler.getReaders().get(0).getChannelCount();
this.geoTranslateVectors = sampler.getGeoTranslateVectors();
if (this.geoTranslateVectors == null) {
System.err.println("This sampler is not based on geo translated images,"
......@@ -1139,8 +1190,8 @@ public class ImageSampler extends Sampler {
this.endY = end / sampler.imageWidth;
}
this.imageWidth = sampler.imageWidth;
this.readers = sampler.readers;
this.channelCount = sampler.readers.get(0).getChannelCount();
this.readers = sampler.getReaders();
this.channelCount = sampler.getReaders().get(0).getChannelCount();
this.geoTranslateVectors = sampler.getGeoTranslateVectors();
if (this.geoTranslateVectors == null) {
System.err.println("This sampler is not based on geo translated images,"
......@@ -1200,4 +1251,57 @@ public class ImageSampler extends Sampler {
}
}
@Override
public void endProgress()
{
this.progress = this.progressM;
}
@Override
public int getProgress()
{
return (int) (((double) this.progress / (double) this.progressM) * 100.0);
}
@Override
public void incProgress()
{
this.progress+=progressM/10;
}