use of ij.ImagePlus in project bioformats by openmicroscopy.
the class LociFunctions method openThumbImage.
public void openThumbImage(String title, Double no) throws FormatException, IOException {
ImporterOptions options = new ImporterOptions();
options.setWindowless(true);
options.setId(r.getCurrentFile());
options.setCrop(true);
options.setSpecifyRanges(true);
options.setSeriesOn(r.getSeries(), true);
int[] zct = r.getZCTCoords(no.intValue());
options.setCBegin(r.getSeries(), zct[1]);
options.setZBegin(r.getSeries(), zct[0]);
options.setTBegin(r.getSeries(), zct[2]);
options.setCEnd(r.getSeries(), zct[1]);
options.setZEnd(r.getSeries(), zct[0]);
options.setTEnd(r.getSeries(), zct[2]);
ImportProcess process = new ImportProcess(options);
process.execute();
ImagePlusReader reader = new ImagePlusReader(process);
final ImagePlus imp = reader.openThumbImagePlus()[0];
Calibrator calibrator = new Calibrator(process);
calibrator.applyCalibration(imp);
process.getReader().close();
imp.show();
}
use of ij.ImagePlus in project TrakEM2 by trakem2.
the class Cache method put.
/**
* @param maxdim is max(width, height) of the Patch wrapping @param imp;
* that is, the dimensions of the mipmap image.
*/
public final void put(final long id, final ImagePlus imp, final int maxdim) {
Pyramid p = pyramids.getValue(id);
if (null == p) {
p = new Pyramid(id, imp, maxdim);
pyramids.put(id, p);
append(p);
//
// may be null, in which case it is not stored in imps
final String path = getPath(imp);
// u is null if path is null
final ImagePlusUsers u = imps.getValue(path);
if (null == u) {
// AFTER adding it to the pyramids
fit(Cache.size(imp));
if (null != path)
imps.put(path, new ImagePlusUsers(imp, id));
} else {
u.addUser(id);
}
//
count++;
} else {
update(p);
final ImagePlus pyrimp = p.getImagePlus();
if (null == pyrimp)
count++;
else if (imp != pyrimp) {
// Remove from old
final String path1 = getPath(pyrimp);
final ImagePlusUsers u1 = imps.getValue(path1);
u1.removeUser(id, path1);
// Add to new, which may have to be created
final String path2 = getPath(imp);
final ImagePlusUsers u2 = imps.getValue(path2);
if (null == u2) {
if (null != path2) {
imps.put(path2, new ImagePlusUsers(imp, id));
}
} else {
u2.addUser(id);
}
}
fit(p.replace(imp));
}
}
use of ij.ImagePlus in project TrakEM2 by trakem2.
the class Cache method removeImagePlus.
private final ImagePlus removeImagePlus(final Pyramid p) {
if (null == p)
return null;
final ImagePlus pyrimp = p.getImagePlus();
if (null == pyrimp)
return null;
final ImagePlus imp = pyrimp;
p.setImagePlus(null);
//
final String path = getPath(imp);
final ImagePlusUsers u = imps.getValue(path);
if (null != u) {
u.removeUser(p.id, path);
}
if (null == u || u.users.isEmpty()) {
// Reclaim space only if the ImagePlus is no longer referenced
// (u is null if the ImagePlus was preprocessed)
addBytes(p.replace(null));
count--;
//
if (0 == p.n_images) {
p.interval.removeEntry(p.id);
pyramids.removeEntry(p.id);
}
}
return imp;
}
use of ij.ImagePlus in project TrakEM2 by trakem2.
the class Cache method get.
public final ImagePlus get(final long id) {
final Pyramid p = pyramids.getValue(id);
if (null == p)
return null;
final ImagePlus pyrimp = p.getImagePlus();
if (null == pyrimp)
return null;
update(p);
return pyrimp;
}
use of ij.ImagePlus in project TrakEM2 by trakem2.
the class Cache method removeAndFlushSome.
public final long removeAndFlushSome(int n) {
long size = 0;
while (intervals.size() > 0) {
final TypedHashMap<Long, Pyramid> interval = intervals.getFirst();
for (final Iterator<Pyramid> it = interval.values().iterator(); it.hasNext(); ) {
final Pyramid p = it.next();
final ImagePlus pyrimp = p.getImagePlus();
if (null != pyrimp) {
final String path = getPath(pyrimp);
final ImagePlusUsers u = imps.getValue(path);
if (null == path || null == u || 1 == u.users.size()) {
//
imps.removeEntry(path);
//
final long s = p.replace(null);
size -= s;
addBytes(s);
// the imp may need cleanup
p.replace(null);
n--;
count--;
if (0 == n) {
if (0 == p.n_images) {
pyramids.removeEntry(p.id);
it.remove();
if (interval.isEmpty())
intervals.removeFirst();
}
return size;
}
}
}
for (int i = 0; i < p.images.length; i++) {
if (null == p.images[i])
continue;
final long s = p.replace(null, i);
size -= s;
addBytes(s);
n--;
count--;
if (0 == n) {
if (0 == p.n_images) {
pyramids.removeEntry(p.id);
it.remove();
if (interval.isEmpty())
intervals.removeFirst();
}
return size;
}
}
pyramids.removeEntry(p.id);
// from the interval
it.remove();
}
intervals.removeFirst();
}
return size;
}
Aggregations