use of org.ddogleg.struct.DogArray_F32 in project BoofCV by lessthanoptimal.
the class ImplMedianSortNaive method process.
/**
* Performs a median filter.
*
* @param input Raw input image.
* @param output Filtered image.
* @param radiusX Size of the filter region. x-axis
* @param radiusY Size of the filter region. Y-axis
* @param workArrays (Optional) Storage for internal workspace. Nullable.
*/
public static void process(GrayF32 input, GrayF32 output, int radiusX, int radiusY, @Nullable GrowArray<DogArray_F32> workArrays) {
final int w = 2 * radiusX + 1;
final int h = 2 * radiusY + 1;
workArrays = BoofMiscOps.checkDeclare(workArrays, DogArray_F32::new);
// CONCURRENT_REMOVE_BELOW
DogArray_F32 workspace = workArrays.grow();
// CONCURRENT_BELOW BoofConcurrency.loopBlocks(0, input.height, h, workArrays, (workspace,y0,y1)->{
final int y0 = 0, y1 = input.height;
float[] workArray = BoofMiscOps.checkDeclare(workspace, w * h, false);
for (int y = y0; y < y1; y++) {
int minI = y - radiusY;
int maxI = y + radiusY + 1;
// bound the y-axis inside the image
if (minI < 0)
minI = 0;
if (maxI > input.height)
maxI = input.height;
for (int x = 0; x < input.width; x++) {
int minJ = x - radiusX;
int maxJ = x + radiusX + 1;
// bound the x-axis to be inside the image
if (minJ < 0)
minJ = 0;
if (maxJ > input.width)
maxJ = input.width;
int index = 0;
for (int i = minI; i < maxI; i++) {
for (int j = minJ; j < maxJ; j++) {
workArray[index++] = input.unsafe_get(j, i);
}
}
// use quick select to avoid sorting the whole list
float median = QuickSelect.select(workArray, index / 2, index);
output.set(x, y, median);
}
}
// CONCURRENT_ABOVE }});
}
use of org.ddogleg.struct.DogArray_F32 in project BoofCV by lessthanoptimal.
the class PointCloudViewerFX method addCloud.
@Override
public void addCloud(List<Point3D_F64> cloud) {
DogArray_F32 fcloud = new DogArray_F32();
fcloud.resize(cloud.size() * 3);
int fidx = 0;
for (int i = 0; i < cloud.size(); i++) {
Point3D_F64 p = cloud.get(i);
fcloud.data[fidx++] = (float) p.x;
fcloud.data[fidx++] = (float) p.y;
fcloud.data[fidx++] = (float) p.z;
}
Platform.runLater(() -> panel.addCloud(fcloud));
}
use of org.ddogleg.struct.DogArray_F32 in project BoofCV by lessthanoptimal.
the class PointCloudViewerApp method openFile.
public void openFile() {
File selected = BoofSwingUtil.fileChooser("PointCloudViewer", frame, true, ".", null, BoofSwingUtil.FileTypes.FILES);
if (selected == null)
return;
// Make it so open file can't be called twice
BoofSwingUtil.recursiveEnable(menuBar, false);
// Load it in a thread as to not lock the GUI
new Thread(() -> {
PointCloudWriter.CloudArraysF32 cloud = new PointCloudWriter.CloudArraysF32();
try {
InputStream input = new FileInputStream(selected);
PointCloudIO.load(PointCloudIO.Format.PLY, input, cloud);
} catch (IOException e) {
BoofSwingUtil.warningDialog(frame, e);
BoofSwingUtil.recursiveEnable(menuBar, true);
return;
}
// Select an initial view location based on the point cloud
final int N = cloud.cloudXyz.size / 3;
float x = 0, y = 0, z = 0;
for (int i = 0; i < N; i++) {
x += cloud.cloudXyz.data[i * 3];
y += cloud.cloudXyz.data[i * 3 + 1];
z += cloud.cloudXyz.data[i * 3 + 2];
}
x /= N;
y /= N;
z /= N;
DogArray_F32 distances = new DogArray_F32();
distances.resize(N);
for (int i = 0; i < N; i++) {
float X = cloud.cloudXyz.data[i * 3];
float Y = cloud.cloudXyz.data[i * 3 + 1];
float Z = cloud.cloudXyz.data[i * 3 + 2];
distances.data[i] = UtilPoint3D_F32.distance(x, y, z, X, Y, Z);
}
Se3_F64 worldToCamera = new Se3_F64();
worldToCamera.T.setTo(x, y, z);
// TODO pick a better method for selecting the initial step size
distances.sort();
double baseline = distances.getFraction(0.001);
System.out.println("baseline = " + baseline);
viewer.periodBaseline = baseline * 10;
viewer.translateBaseline = baseline;
viewer.getViewer().setCameraHFov(UtilAngle.radian(100));
SwingUtilities.invokeLater(() -> {
viewer.handleControlChange();
viewer.clearPoints();
viewer.getViewer().addCloud(cloud.cloudXyz, cloud.cloudRgb);
viewer.getViewer().setCameraToWorld(worldToCamera);
viewer.repaint();
BoofSwingUtil.recursiveEnable(menuBar, true);
});
}).start();
}
use of org.ddogleg.struct.DogArray_F32 in project BoofCV by lessthanoptimal.
the class MultiBaselineDisparityMedian method computeFused.
/**
* Computes the fused output image. The median value is used if a pixel has more than 2 values. Otherwise the
* mean will be used.
*
* @return true if the disparity image is not entirely empty
*/
boolean computeFused(GrayF32 disparity) {
// If there's one pixel with a valid value this will pass
boolean singleValidPixel = false;
for (int y = 0; y < fused.height; y++) {
int indexOut = disparity.startIndex + y * disparity.stride;
for (int x = 0; x < fused.width; x++) {
DogArray_F32 values = fused.get(x, y);
float outputValue;
if (values.size == 0) {
// mark this pixel as invalid. The disparity will be rescaled later on and the max value at this
// time isn't known
outputValue = Float.MAX_VALUE;
} else if (values.size == 1) {
singleValidPixel = true;
outputValue = values.data[0];
} else if (values.size == 2) {
singleValidPixel = true;
outputValue = 0.5f * (values.data[0] + values.data[1]);
} else {
// median value
outputValue = QuickSelect.select(values.data, values.size / 2, values.size);
singleValidPixel = true;
}
disparity.data[indexOut++] = outputValue;
}
}
return singleValidPixel;
}
use of org.ddogleg.struct.DogArray_F32 in project BoofCV by lessthanoptimal.
the class TestQrCodeBinaryGridReader method readBitIntensity_count.
/**
* Checks to see if the expected number of points was read
*/
@Test
void readBitIntensity_count() {
DogArray_F32 intensity = new DogArray_F32();
// add a value to it to make sure it's not cleared
intensity.add(5);
QrCodeDistortedChecks helper = createDistortionCheck();
QrCodeBinaryGridReader<GrayF32> reader = new QrCodeBinaryGridReader<>(GrayF32.class);
reader.setImage(helper.image);
reader.setMarker(helper.qr);
reader.readBitIntensity(10, 11, intensity);
// Make sure the expected number of points was read
// If that changes you need to hunt down places '5' was hard coded. Sorry for that.
assertEquals(1 + QrCodeBinaryGridReader.BIT_INTENSITY_SAMPLES, intensity.size);
}
Aggregations