forked from jayunruh/Jay_Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduplicate_hs_slice_jru_v1.java
More file actions
99 lines (96 loc) · 3.01 KB
/
Copy pathduplicate_hs_slice_jru_v1.java
File metadata and controls
99 lines (96 loc) · 3.01 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*******************************************************************************
* Copyright (c) 2012 Jay Unruh, Stowers Institute for Medical Research.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v2.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
******************************************************************************/
import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;
public class duplicate_hs_slice_jru_v1 implements PlugIn {
public void run(String arg) {
GenericDialog gd=new GenericDialog("Options");
String[] choices={"Channel","Z Slice","Time Point"};
gd.addChoice("Duplicate_Current",choices,choices[0]);
gd.showDialog(); if(gd.wasCanceled()){return;}
int index2=gd.getNextChoiceIndex();
ImagePlus imp=WindowManager.getCurrentImage();
int width=imp.getWidth();
int height=imp.getHeight();
int channels=imp.getNChannels();
int slices=imp.getNSlices();
int frames=imp.getNFrames();
ImageStack stack=imp.getStack();
int currchan=imp.getChannel()-1;
int currslice=imp.getSlice()-1;
int currframe=imp.getFrame()-1;
ImageStack retstack=new ImageStack(width,height);
if(index2==0){
for(int i=0;i<frames;i++){
for(int j=0;j<slices;j++){
for(int k=0;k<channels;k++){
if(k==currchan){
int index=k+j*channels+i*slices*channels+1;
retstack.addSlice(stack.getSliceLabel(index),stack.getPixels(index));
}
}
}
}
ImagePlus imp2=new ImagePlus("Duplicate",retstack);
imp2.copyScale(imp);
imp2.setOpenAsHyperStack(true);
imp2.setDimensions(1,slices,frames);
imp2.show();
}
if(index2==1){
for(int i=0;i<frames;i++){
for(int j=0;j<slices;j++){
for(int k=0;k<channels;k++){
if(j==currslice){
int index=k+j*channels+i*slices*channels+1;
retstack.addSlice(stack.getSliceLabel(index),stack.getPixels(index));
}
}
}
}
ImagePlus imp2=new ImagePlus("Duplicate",retstack);
imp2.copyScale(imp);
imp2.setOpenAsHyperStack(true);
imp2.setDimensions(channels,1,frames);
if(channels>1 && imp.isComposite()){
CompositeImage ci=new CompositeImage(imp2,((CompositeImage)imp).getMode());
ci.copyLuts(imp);
ci.show();
} else {
imp2.show();
}
}
if(index2==2){
int counter=0;
for(int i=0;i<frames;i++){
for(int j=0;j<slices;j++){
for(int k=0;k<channels;k++){
if(i==currframe){
int index=k+j*channels+i*slices*channels+1;
retstack.addSlice(stack.getSliceLabel(index),stack.getPixels(index));
}
}
}
}
ImagePlus imp2=new ImagePlus("Duplicate",retstack);
imp2.copyScale(imp);
imp2.setOpenAsHyperStack(true);
imp2.setDimensions(channels,slices,1);
if(channels>1 && imp.isComposite()){
CompositeImage ci=new CompositeImage(imp2,((CompositeImage)imp).getMode());
ci.copyLuts(imp);
ci.show();
} else {
imp2.show();
}
}
}
}