-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThumbnailItem.java
More file actions
65 lines (51 loc) · 1.72 KB
/
Copy pathThumbnailItem.java
File metadata and controls
65 lines (51 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import ij.ImagePlus;
import ij.process.ImageProcessor;
import java.awt.Image;
import java.awt.image.BufferedImage;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Juanjo Vega, Jesus Cuenca
*/
public class ThumbnailItem {
private final static int SIZE = 50;
private Image thumbnail;
public ThumbnailItem(ImagePlus imp) {
thumbnail = createThumbnail(imp);
}
private Image createThumbnail(ImagePlus imp) {
// Scales image.
int W = imp.getWidth(), H = imp.getHeight();
int w = W >= H ? SIZE : -1;
int h = W < H ? SIZE : -1;
ImagePlus toThumbnail = imp;
if(imp.getNSlices() > 1)
toThumbnail=getSlice(imp,imp.getCurrentSlice());
Image i = toThumbnail.getImage();
if (W > SIZE || H > SIZE) {
i = i.getScaledInstance(w, h, Image.SCALE_FAST);
}
// Draws it centered in a transparent image.
BufferedImage bimage = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_ARGB);
w = i.getWidth(null);
h = i.getHeight(null);
int x = SIZE / 2 - w / 2;
int y = SIZE / 2 - h / 2;
bimage.getGraphics().drawImage(i, x, y, null);
return bimage;
}
public Image getThumbnail() {
return thumbnail;
}
public ImagePlus getSlice(ImagePlus imp, int z){
int n1 = imp.getStackIndex(1, z, 1);
ImageProcessor sliceIp = imp.getStack().getProcessor(n1);
ImageProcessor ip=imp.getProcessor();
sliceIp.setThreshold(ip.getMinThreshold(), ip.getMaxThreshold(), Distance_Measure.getThresholdMode());
ImagePlus result= new ImagePlus("Slice",sliceIp);
return result;
}
}