This commit is contained in:
gobbo_a
2016-09-15 17:15:01 +02:00
parent ed6fbc94d6
commit 721762dbc1
3 changed files with 107 additions and 98 deletions

View File

@@ -1,13 +1,13 @@
#Thu Sep 15 09:19:12 CEST 2016
colormap=Rainbow
#Thu Sep 15 15:24:56 CEST 2016
colormap=Temperature
colormapAutomatic=true
colormapMax=0.0
colormapMin=0.0
flipHorizontally=false
flipVertically=false
grayscale=false
imageHeight=2160
imageWidth=2560
imageHeight=1024
imageWidth=1280
invert=false
rescaleFactor=1.0
rescaleOffset=0.0
@@ -15,12 +15,12 @@ roiHeight=-1
roiWidth=-1
roiX=0
roiY=0
rotation=1.0
rotation=0.0
rotationCrop=true
scale=1.0
spatialCalOffsetX=-1057.0
spatialCalOffsetY=-1420.0
spatialCalScaleX=8.51063829787234
spatialCalScaleY=8.559201141226819
spatialCalOffsetX=NaN
spatialCalOffsetY=NaN
spatialCalScaleX=NaN
spatialCalScaleY=NaN
spatialCalUnits=mm
transpose=false

View File

@@ -11,6 +11,11 @@
<Component class="javax.swing.ButtonGroup" name="buttonGroup4">
</Component>
</NonVisualComponents>
<Properties>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[873, 150]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
@@ -39,8 +44,8 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanel4" max="32767" attributes="0"/>
<Component id="jPanel1" max="32767" attributes="0"/>
<Component id="jPanel4" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
</Group>
@@ -100,7 +105,7 @@
<Component id="buttonSetup" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="renderer" max="32767" attributes="0"/>
<Component id="renderer" pref="638" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="12" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="buttonPause" alignment="3" min="-2" max="-2" attributes="0"/>
@@ -215,6 +220,11 @@
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel4">
<Properties>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[235, 128]"/>
</Property>
</Properties>
<Layout>
<DimensionLayout dim="0">
@@ -223,7 +233,7 @@
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="jPanel3" max="32767" attributes="0"/>
<Component id="jPanel2" alignment="0" pref="0" max="32767" attributes="0"/>
<Component id="jPanel2" alignment="0" max="32767" attributes="0"/>
<Component id="jPanel5" alignment="0" max="32767" attributes="0"/>
<Component id="panelScreen" alignment="0" max="32767" attributes="0"/>
<Component id="panelScreen1" alignment="1" max="32767" attributes="0"/>
@@ -429,7 +439,7 @@
<Component id="spinnerMax" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace pref="20" max="32767" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="buttonHistogram" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>

View File

@@ -38,13 +38,11 @@ import ch.psi.pshell.imaging.Renderer.Profile;
import static ch.psi.pshell.imaging.RendererMenu.PEN_MARKER;
import ch.psi.pshell.imaging.RendererMode;
import ch.psi.pshell.imaging.Source;
import ch.psi.pshell.imaging.Utils;
import ch.psi.pshell.scripting.InterpreterResult;
import ch.psi.pshell.scripting.ScriptManager;
import ch.psi.utils.Arr;
import ch.psi.utils.ArrayProperties;
import ch.psi.utils.Convert;
import ch.psi.utils.Str;
import ch.psi.utils.swing.Editor.EditorDialog;
import java.awt.Color;
import java.awt.Component;
@@ -73,7 +71,6 @@ public class ScreenPanel extends Panel {
public ScreenPanel() {
initComponents();
renderer.setPersistenceFile(Paths.get(getController().getSetup().getContextPath(), "Renderer_Cameras.bin"));
renderer.setProfileFactor(4);
setPersistedComponents(new Component[]{buttonCamtool, buttonDirect});
comboCameras.setEnabled(false);
if (App.hasArgument("poll")) {
@@ -91,6 +88,7 @@ public class ScreenPanel extends Panel {
ex.printStackTrace();
}
}
showFit=buttonFit.isSelected();
}
@Override
@@ -114,6 +112,7 @@ public class ScreenPanel extends Panel {
JDialog histogramDialog;
DiscretePositioner screen;
DiscretePositioner filter;
boolean showFit;
//Overridable callbacks
@Override
@@ -125,13 +124,12 @@ public class ScreenPanel extends Panel {
((Source)getDevice("image")).addListener(new ImageListener() {
@Override
public void onImage(Object o, BufferedImage bi, Data data) {
if (bi == null) {
if ((bi == null)||(!showFit)) {
fitOv = null;
} else {
Overlay[] profile = renderer.getProfileOverlays();
profile = ((profile != null) && (profile.length==4)) ? getFitOverlays(bi) : null;
renderer.updateOverlays(profile, fitOv);
fitOv = profile;
Overlay[] fo = getFitOverlays(data);
renderer.updateOverlays(fo, fitOv);
fitOv = fo;
}
}
@Override
@@ -374,16 +372,14 @@ public class ScreenPanel extends Panel {
camera.addListener(new ImageListener() {
@Override
public void onImage(Object o, BufferedImage bi, Data data) {
if (bi == null) {
if ((bi == null)|| (!showFit)) {
renderer.removeOverlays(fitOv);
fitOv = null;
} else {
//System.out.println(bi.getWidth() + " - " + bi.getHeight());
if (!renderer.isPaused() && buttonFit.isSelected()){
Overlay[] profile = renderer.getProfileOverlays();
profile = ((profile != null) && (profile.length==4)) ? getFitOverlays(bi) : null;
renderer.updateOverlays(profile, fitOv);
fitOv = profile;
if (!renderer.isPaused()){
Overlay[] fo = getFitOverlays(data);
renderer.updateOverlays(fo, fitOv);
fitOv = fo;
}
}
}
@@ -538,76 +534,75 @@ public class ScreenPanel extends Panel {
Pen fitPen = new Pen(new Color(192, 105, 0), 1);
Pen crossPen = new Pen(new Color(192, 105, 0), 1);
Overlay[] getFitOverlays(BufferedImage img){
Overlay[] getFitOverlays(Data data){
Overlays.Polyline hpoly = null;
Overlays.Polyline vpoly = null;
Double xMean = null; Double xSigma = null;
Double yMean = null; Double ySigma = null;
Profile profile = renderer.getProfile();
if ((profile != Profile.None) && (img != null)) {
img = Utils.grayscale(img);
if (profile.hasVertical()) {
try {
double[] sum = (double[]) Convert.toDouble(Utils.integrateVertically(img));
int[] x = Arr.indexesInt(sum.length);
DescriptiveStatistics stats = new DescriptiveStatistics(sum);
double min = stats.getMin();
for (int i=0; i< sum.length; i++){
sum[i] = sum[i] - min;
}
double[] gaussian = fitGaussian(sum, x);
if (gaussian!=null){
// System.out.println("Norm: " + gaussian[0] + " Mean: " + gaussian[1] + " Sigma: " + gaussian[2]+ " Min: " + min);
//Only aknowledge beam fully inside the image and peak over 3% of min
if ((gaussian[2] < sum.length * 0.45) && (gaussian[0] > min * 0.03)){
xMean = gaussian[1];
xSigma = gaussian[2];
gaussian[0]+=min;
double[] fit = getFitFunction(gaussian, x);
int[] y = new int[x.length];
for (int i = 0; i < x.length; i++) {
y[i] = (int) (img.getHeight() - 1 - (((double) fit[i]) / 255 / renderer.getProfileFactor()));
}
vpoly = new Overlays.Polyline(fitPen, x, y);
}
} else {
//System.out.println("Fit failure");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (profile.hasHorizontal()) {
try {
double[] sum = (double[]) Convert.toDouble(Utils.integrateHorizontally(img));
int[] x = Arr.indexesInt(sum.length);
DescriptiveStatistics stats = new DescriptiveStatistics(sum);
double min = stats.getMin();
for (int i=0; i< sum.length; i++){
sum[i] = sum[i] - min;
}
double[] gaussian = fitGaussian(sum, x);
if (gaussian!=null){
//Only aknowledge beam fully inside the image and peak over 3% of min
if ((gaussian[2] < sum.length * 0.45) && (gaussian[0] > min * 0.03)){
yMean = gaussian[1];
ySigma = gaussian[2];
gaussian[0]+=min;
double[] fit = getFitFunction(gaussian, x);
if (data != null) {
//img = Utils.grayscale(img);
double maxPlot = 255.0;
try {
double[] sum = (double[]) Convert.toDouble(data.integrateVertically());
int[] x = Arr.indexesInt(sum.length);
DescriptiveStatistics stats = new DescriptiveStatistics(sum);
double min = stats.getMin();
for (int i=0; i< sum.length; i++){
sum[i] = sum[i] - min;
}
maxPlot = 4 * stats.getMax() /data.getHeight() ;
int[] y = new int[x.length];
for (int i = 0; i < x.length; i++) {
y[i] = (int) (((double) fit[i]) / 255 / renderer.getProfileFactor());
}
hpoly = new Overlays.Polyline(fitPen, y, x);
}
double[] gaussian = fitGaussian(sum, x);
if (gaussian!=null){
if ((gaussian[2] < sum.length * 0.45) && (gaussian[0] > min * 0.03)){
xMean = gaussian[1];
xSigma = gaussian[2];
gaussian[0]+=min;
double[] fit = getFitFunction(gaussian, x);
int[] y = new int[x.length];
for (int i = 0; i < x.length; i++) {
y[i] = (int) (data.getHeight() - 1 - (fit[i] / maxPlot));
}
vpoly = new Overlays.Polyline(fitPen, x, y);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
try {
double[] sum = (double[]) Convert.toDouble(data.integrateHorizontally());
int[] x = Arr.indexesInt(sum.length);
DescriptiveStatistics stats = new DescriptiveStatistics(sum);
double min = stats.getMin();
for (int i=0; i< sum.length; i++){
sum[i] = sum[i] - min;
}
maxPlot = 4 * stats.getMax() /data.getWidth() ;
double[] gaussian = fitGaussian(sum, x);
if (gaussian!=null){
//Only aknowledge beam fully inside the image and peak over 3% of min
if ((gaussian[2] < sum.length * 0.45) && (gaussian[0] > min * 0.03)){
yMean = gaussian[1];
ySigma = gaussian[2];
gaussian[0]+=min;
double[] fit = getFitFunction(gaussian, x);
int[] y = new int[x.length];
for (int i = 0; i < x.length; i++) {
y[i] = (int) (fit[i] / maxPlot);
}
hpoly = new Overlays.Polyline(fitPen, y, x);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
Overlays.Crosshairs cross= null;
if ((xMean!=null) && (yMean!=null)){
cross = new Overlays.Crosshairs(crossPen,
@@ -935,6 +930,8 @@ public class Camtool extends ArraySource {
valueFilter = new ch.psi.pshell.swing.DeviceValuePanel();
comboFilter = new javax.swing.JComboBox();
setPreferredSize(new java.awt.Dimension(873, 150));
buttonGrabBackground.setText("Grab Background");
buttonGrabBackground.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
@@ -1062,7 +1059,7 @@ public class Camtool extends ArraySource {
.addComponent(buttonConfig)
.addComponent(buttonSetup))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 638, Short.MAX_VALUE)
.addGap(12, 12, 12)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(buttonPause)
@@ -1076,6 +1073,8 @@ public class Camtool extends ArraySource {
jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {comboCameras, textState});
jPanel4.setPreferredSize(new java.awt.Dimension(235, 128));
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Zoom"));
buttonGroup1.add(buttonZoomFit);
@@ -1282,7 +1281,7 @@ public class Camtool extends ArraySource {
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(spinnerMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(buttonHistogram)
.addContainerGap())
);
@@ -1395,7 +1394,7 @@ public class Camtool extends ArraySource {
.addContainerGap()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(panelScreen, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(panelScreen1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
@@ -1432,8 +1431,8 @@ public class Camtool extends ArraySource {
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, 0)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
);
}// </editor-fold>//GEN-END:initComponents
@@ -1519,7 +1518,7 @@ public class Camtool extends ArraySource {
private void buttonFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonFitActionPerformed
try {
renderer.setProfile(buttonFit.isSelected() ? Profile.Both :Profile.None);
showFit=buttonFit.isSelected();
if (!buttonFit.isSelected()){
renderer.removeOverlays(fitOv);
fitOv = null;