boofcv.struct.image.GrayU8 Java Examples
The following examples show how to use
boofcv.struct.image.GrayU8.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImageDesc.java From MtgDesktopCompanion with GNU General Public License v3.0 | 6 votes |
public ImageDesc(BufferedImage in, BufferedImage flipin) { if(!AverageHash.isInitiated()) { AverageHash.init(2, 2); } hash = AverageHash.avgHash(in,2,2); if(flipin != null) { flipped = AverageHash.avgHash(flipin,2,2); } int[] histogram = new int[256]; int[] transform = new int[256]; GrayU8 img = ConvertBufferedImage.convertFromSingle(in, null, GrayU8.class); GrayU8 norm = img.createSameShape(); ImageStatistics.histogram(img,0,histogram); EnhanceImageOps.equalize(histogram, transform); EnhanceImageOps.applyTransform(img, transform, norm); GrayF32 normf = new GrayF32(img.width,img.height); ConvertImage.convert(norm, normf); desc.reset(); describeImage(normf,desc); }
Example #2
Source File: PathList.java From cineast with MIT License | 6 votes |
public static LinkedList<PyramidKltFeature> denseSampling(GrayU8 image, GrayS16[] derivX, GrayS16[] derivY, int samplingInterval, PkltConfig configKlt, ImageGradient<GrayU8, GrayS16> gradient, PyramidDiscrete<GrayU8> pyramid, PyramidKltTracker<GrayU8, GrayS16> tracker) { LinkedList<PyramidKltFeature> tracks = new LinkedList<PyramidKltFeature>(); pyramid.process(image); derivX = declareOutput(pyramid, derivX); derivY = declareOutput(pyramid, derivY); PyramidOps.gradient(pyramid, gradient, derivX, derivY); tracker.setImage(pyramid, derivX, derivY); for (int y = 0; y < image.height; y += samplingInterval) { for (int x = 0; x < image.width; x += samplingInterval) { PyramidKltFeature t = new PyramidKltFeature(configKlt.pyramidScaling.length, configKlt.templateRadius); t.setPosition(x, y); tracker.setDescription(t); tracks.add(t); } } return tracks; }
Example #3
Source File: MaskGenerator.java From cineast with MIT License | 6 votes |
public static ArrayList<GrayU8> gaussianFilterTemporal(ArrayList<GrayU8> input, ArrayList<GrayU8> output, int spatialRadius){ int width = input.get(0).getWidth(); int height = input.get(0).getHeight(); int len = input.size(); Kernel1D_F32 kernel = FactoryKernelGaussian.gaussian(Kernel1D_F32.class,-1,spatialRadius); float divisor = kernel.computeSum(); int data1D[] = new int[len + 2*kernel.offset]; for (int x = 0; x < width; ++x){ for (int y = 0; y < height; ++y){ for(int i = 0; i < len; ++i){ data1D[i + kernel.offset] = input.get(i).get(x, y); } for(int i = 0; i < len; ++i){ int total = 0; for (int k = 0; k < kernel.width; ++k){ total += (data1D[i+k] & 0xFF) * kernel.data[k]; } output.get(i).set(x, y, Math.round(total/divisor)); } } } return output; }
Example #4
Source File: MaskGenerator.java From cineast with MIT License | 6 votes |
public static ArrayList<GrayU8> smoothMasks(ArrayList<GrayU8> input, ArrayList<GrayU8> output, int spatialRadius, int temporalRadius, double multipyFactor, int threshold){ if(input == null || input.isEmpty()){ return input; } if(output == null){ output = createNewMasks(input); } if(output.size() != input.size()){ throw new IllegalArgumentException("size of input and output do not match. input: "+input.size()+" output: "+output.size()); } multiply3D(input, input, multipyFactor); gaussianFilter3D(input, output, spatialRadius, temporalRadius); threshold3D(output,output,threshold); return output; }
Example #5
Source File: MaskGenerator.java From cineast with MIT License | 6 votes |
public static ArrayList<GrayU8> getFgMasksByNN(List<VideoFrame> videoFrames, List<Pair<Integer, LinkedList<Point2D_F32>>> foregroundPaths, List<Pair<Integer, LinkedList<Point2D_F32>>> backgroundPaths) { if (videoFrames == null || videoFrames.isEmpty() || foregroundPaths == null) { return null; } ArrayList<GrayU8> masks = generateMasksFromPath(videoFrames, foregroundPaths, backgroundPaths); ArrayList<GrayU8> masksSmoothed1 = createNewMasks(masks); smoothMasks(masks, masksSmoothed1, 21, 2, 64, 26); ArrayList<GrayU8> masksSmoothed2 = createNewMasks(masks); smoothMasks(masksSmoothed1, masksSmoothed2, 11, 2, 64, 26); //multiply3D(masksSmoothed2,masksSmoothed2,255); return masksSmoothed2; }
Example #6
Source File: MaskGenerator.java From cineast with MIT License | 6 votes |
public static ArrayList<GrayU8> getFgMasksByFilter(List<VideoFrame> videoFrames, List<Pair<Integer, LinkedList<Point2D_F32>>> foregroundPaths, List<Pair<Integer, LinkedList<Point2D_F32>>> backgroundPaths) { if (videoFrames == null || videoFrames.isEmpty() || foregroundPaths == null) { return null; } ArrayList<GrayU8> masksScaled = generateScaledMasksFromPath(videoFrames, foregroundPaths); ArrayList<GrayU8> masksScaledSmoothed1 = createNewMasks(masksScaled); smoothMasks(masksScaled, masksScaledSmoothed1, 4, 2, 64, 26); ArrayList<GrayU8> masks = scaleUpMasks(masksScaledSmoothed1, videoFrames.get(0).getImage().getBufferedImage().getWidth(), videoFrames.get(0).getImage().getBufferedImage().getHeight()); ArrayList<GrayU8> masksSmoothed1 = createNewMasks(masks); smoothMasks(masks, masksSmoothed1, 5, 2, 64, 10); ArrayList<GrayU8> masksSmoothed2 = createNewMasks(masks); smoothMasks(masksSmoothed1, masksSmoothed2, 5, 2, 64, 10); //multiply3D(masksSmoothed2,masksSmoothed2,255); return masksSmoothed2; }
Example #7
Source File: EdgeImg.java From cineast with MIT License | 6 votes |
public static boolean[] getEdgePixels(MultiImage img, boolean[] out) { LOGGER.traceEntry(); if (out == null || out.length != img.getWidth() * img.getHeight()) { out = new boolean[img.getWidth() * img.getHeight()]; } GrayU8 gray = ConvertBufferedImage.convertFrom(img.getBufferedImage(), (GrayU8) null); if(!isSolid(gray)){ getCanny().process(gray, THRESHOLD_LOW, THRESHOLD_HIGH, gray); } for (int i = 0; i < gray.data.length; ++i) { out[i] = (gray.data[i] != 0); } LOGGER.traceExit(); return out; }
Example #8
Source File: MaskGenerator.java From cineast with MIT License | 6 votes |
public static ArrayList<ImageRectangle> getFgBoundingBox(List<VideoFrame> videoFrames, List<Pair<Integer, LinkedList<Point2D_F32>>> foregroundPaths, List<Pair<Integer, LinkedList<Point2D_F32>>> backgroundPaths){ if (videoFrames == null || videoFrames.isEmpty() || foregroundPaths == null) { return null; } ArrayList<ImageRectangle> rects = new ArrayList<ImageRectangle>(); ArrayList<GrayU8> masks = getFgMasksByNN(videoFrames, foregroundPaths, backgroundPaths); for(GrayU8 mask : masks){ ImageRectangle rect = getLargestBoundingBox(mask); rects.add(rect); } return rects; }
Example #9
Source File: EdgeImg.java From cineast with MIT License | 6 votes |
public static List<Boolean> getEdgePixels(MultiImage img, List<Boolean> out) { LOGGER.traceEntry(); if (out == null) { out = new ArrayList<Boolean>(img.getWidth() * img.getHeight()); } else { out.clear(); } BufferedImage withBackground = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = withBackground.getGraphics(); g.setColor(Color.white); g.fillRect(0, 0, img.getWidth(), img.getHeight()); g.drawImage(img.getBufferedImage(), 0, 0, null); GrayU8 gray = ConvertBufferedImage.convertFrom(withBackground, (GrayU8) null); if(!isSolid(gray)){ getCanny().process(gray, THRESHOLD_LOW, THRESHOLD_HIGH, gray); } for (int i = 0; i < gray.data.length; ++i) { out.add(gray.data[i] != 0); } LOGGER.traceExit(); return out; }
Example #10
Source File: ContourHelper.java From cineast with MIT License | 6 votes |
/** * Applies a contour-detection algorithm on the provided image and returns a list of detected contours. First, the image * is converted to a BinaryImage using a threshold algorithm (Otsu). Afterwards, blobs in the image are detected using * an 8-connect rule. * * This method provides the best results if the image is a black & white, i.e. factually binary, image! * See {@link ContourHelper#segmentImageByColour(BufferedImage,float[])} to convert a coloured image to a binary image. * * @param image BufferedImage in which contours should be detected. * @return List of contours. */ public static List<Contour> getContours(BufferedImage image) { /* Draw a black frame around to image so as to make sure that all detected contours are internal contours. */ BufferedImage resized = new BufferedImage(image.getWidth() + 4, image.getHeight() + 4, image.getType()); Graphics g = resized.getGraphics(); g.setColor(Color.BLACK); g.fillRect(0,0,resized.getWidth(),resized.getHeight()); g.drawImage(image, 2,2, image.getWidth(), image.getHeight(), null); /* Convert to BufferedImage to Gray-scale image and prepare Binary image. */ GrayF32 input = ConvertBufferedImage.convertFromSingle(resized, null, GrayF32.class); GrayU8 binary = new GrayU8(input.width,input.height); GrayS32 label = new GrayS32(input.width,input.height); /* Select a global threshold using Otsu's method and apply that threshold. */ double threshold = GThresholdImageOps.computeOtsu(input, 0, 255); ThresholdImageOps.threshold(input, binary,(float)threshold,true); /* Remove small blobs through erosion and dilation; The null in the input indicates that it should internally * declare the work image it needs this is less efficient, but easier to code. */ GrayU8 filtered = BinaryImageOps.erode8(binary, 1, null); filtered = BinaryImageOps.dilate8(filtered, 1, null); /* Detect blobs inside the image using an 8-connect rule. */ return BinaryImageOps.contour(filtered, ConnectRule.EIGHT, label); }
Example #11
Source File: HOG.java From cineast with MIT License | 6 votes |
/** * */ @Override public void processSegment(SegmentContainer shot) { if (shot.getMostRepresentativeFrame() == VideoFrame.EMPTY_VIDEO_FRAME) { return; } BufferedImage image = shot.getMostRepresentativeFrame().getImage().getBufferedImage(); if (image != null) { DescribeImageDense<GrayU8, TupleDesc_F64> hog = HOGHelper.getHOGDescriptors(image); if (hog != null && hog.getDescriptions().size() > 0) { float[] histogram_f = this.histogram(true, hog.getDescriptions()); this.persist(shot.getId(), new FloatVectorImpl(histogram_f)); } else { LOGGER.warn("No HOG feature could be extracted for segment {}. This is not necessarily an error!", shot.getId()); } } }
Example #12
Source File: EdgeImg.java From cineast with MIT License | 5 votes |
public static boolean isSolid(GrayU8 img){ byte first = img.data[0]; for(byte b : img.data){ if(b != first){ return false; } } return true; }
Example #13
Source File: EdgeImg.java From cineast with MIT License | 5 votes |
private static synchronized CannyEdge<GrayU8, GrayS16> getCanny(){ Thread current = Thread.currentThread(); try { return cannies.get(current); } catch (ExecutionException e) { return null; //NEVER HAPPENS } }
Example #14
Source File: EdgeImg.java From cineast with MIT License | 5 votes |
public static MultiImage getEdgeImg(MultiImage img) { LOGGER.traceEntry(); GrayU8 gray = ConvertBufferedImage.convertFrom(img.getBufferedImage(), (GrayU8) null); if(!isSolid(gray)){ getCanny().process(gray, THRESHOLD_LOW, THRESHOLD_HIGH, gray); } BufferedImage bout = VisualizeBinaryData.renderBinary(gray, false, null); return LOGGER.traceExit(MultiImageFactory.newMultiImage(bout)); }
Example #15
Source File: EdgeList.java From cineast with MIT License | 5 votes |
public static List<EdgeContour> getEdgeList(MultiImage img){ LOGGER.traceEntry(); BufferedImage withBackground = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = withBackground.getGraphics(); g.setColor(Color.white); g.fillRect(0, 0, img.getWidth(), img.getHeight()); g.drawImage(img.getBufferedImage(), 0, 0, null); GrayU8 gray = ConvertBufferedImage.convertFrom(withBackground, (GrayU8) null); CannyEdge<GrayU8, GrayS16> canny = getCanny(); canny.process(gray, THRESHOLD_LOW, THRESHOLD_HIGH, null); List<EdgeContour> _return = canny.getContours(); LOGGER.traceExit(); return _return; }
Example #16
Source File: PathList.java From cineast with MIT License | 5 votes |
public static GrayS16[] declareOutput(PyramidDiscrete<GrayU8> pyramid, GrayS16[] deriv) { if (deriv == null) { deriv = PyramidOps.declareOutput(pyramid, GrayS16.class); } else if (deriv[0].width != pyramid.getLayer(0).width || deriv[0].height != pyramid.getLayer(0).height) { PyramidOps.reshapeOutput(pyramid, deriv); } return deriv; }
Example #17
Source File: PathList.java From cineast with MIT License | 5 votes |
public static LinkedList<PyramidKltFeature> tracking(GrayU8 image, GrayS16[] derivX, GrayS16[] derivY, LinkedList<PyramidKltFeature> tracks, ArrayList<AssociatedPair> tracksPairs, ImageGradient<GrayU8, GrayS16> gradient, PyramidDiscrete<GrayU8> pyramidForeward, PyramidDiscrete<GrayU8> pyramidBackward, PyramidKltTracker<GrayU8, GrayS16> trackerForeward, PyramidKltTracker<GrayU8, GrayS16> trackerBackward ) { pyramidForeward.process(image); derivX = declareOutput(pyramidForeward, derivX); derivY = declareOutput(pyramidForeward, derivY); PyramidOps.gradient(pyramidForeward, gradient, derivX, derivY); trackerForeward.setImage(pyramidForeward, derivX, derivY); ListIterator<PyramidKltFeature> listIterator = tracks.listIterator(); while (listIterator.hasNext()) { PyramidKltFeature track = listIterator.next(); Point2D_F64 pointPrev = new Point2D_F64(track.x, track.y); KltTrackFault ret = trackerForeward.track(track); boolean success = false; if (ret == KltTrackFault.SUCCESS && image.isInBounds((int) track.x, (int) track.y) && trackerForeward.setDescription(track)) { Point2D_F64 pointCur = new Point2D_F64(track.x, track.y); ret = trackerBackward.track(track); if (ret == KltTrackFault.SUCCESS && image.isInBounds((int) track.x, (int) track.y)) { Point2D_F64 pointCurBack = new Point2D_F64(track.x, track.y); if (normalizedDistance(pointPrev, pointCurBack) < backwardTrackingDistanceThreshold) { tracksPairs.add(new AssociatedPair(pointPrev, pointCur)); success = true; } } } if (!success) { listIterator.remove(); } } return tracks; }
Example #18
Source File: EdgeList.java From cineast with MIT License | 5 votes |
private static synchronized CannyEdge<GrayU8, GrayS16> getCanny() { Thread current = Thread.currentThread(); try { return cannies.get(current); } catch (ExecutionException e) { return null; // NEVER HAPPENS } }
Example #19
Source File: MaskGenerator.java From cineast with MIT License | 5 votes |
public static ArrayList<GrayU8> threshold3D(ArrayList<GrayU8> input, ArrayList<GrayU8> output, int threshold){ for (int i = 0; i < input.size(); ++i){ ThresholdImageOps.threshold(input.get(i), output.get(i), threshold, false); } return output; }
Example #20
Source File: MaskGenerator.java From cineast with MIT License | 5 votes |
public static ArrayList<GrayU8> scaleUpMasks(ArrayList<GrayU8> input, int width, int height){ ArrayList<GrayU8> output = new ArrayList<GrayU8>(); for (int i = 0; i < input.size(); ++i){ GrayU8 in = input.get(i); GrayU8 out = new GrayU8(width, height); new FDistort(in, out).scaleExt().apply(); output.add(out); } return output; }
Example #21
Source File: MaskGenerator.java From cineast with MIT License | 5 votes |
public static ArrayList<GrayU8> createNewMasks(ArrayList<GrayU8> input){ ArrayList<GrayU8> output = new ArrayList<GrayU8>(); for (int i = 0; i < input.size(); ++i){ output.add(input.get(i).createSameShape()); } return output; }
Example #22
Source File: EHD.java From cineast with MIT License | 5 votes |
protected static float[] process(MultiImage img, float[] hist) { GrayU8 gray = ConvertBufferedImage.convertFrom(img.getBufferedImage(), (GrayU8) null); int width = img.getWidth(), height = img.getHeight(); for (int x = 0; x < 4; ++x) { for (int y = 0; y < 4; ++y) { GrayU8 subImage = gray .subimage(width * x / 4, height * y / 4, width * (x + 1) / 4, height * (y + 1) / 4, null); int count = 0; int[] tmp = new int[5]; for (int xx = 0; xx < subImage.getWidth() - 1; xx += 2) { for (int yy = 0; yy < subImage.getHeight() - 1; yy += 2) { count++; int index = edgeType( subImage.unsafe_get(xx, yy), subImage.unsafe_get(xx + 1, yy), subImage.unsafe_get(xx, yy + 1), subImage.unsafe_get(xx + 1, yy + 1) ); if (index > -1) { tmp[index]++; } } } int offset = (4 * x + y) * 5; for (int i = 0; i < 5; ++i) { hist[offset + i] += ((float) tmp[i]) / (float) count; } } } return hist; }
Example #23
Source File: HOGCodebookGenerator.java From cineast with MIT License | 5 votes |
/** * Processes the content (i.e. creates descriptors) and add the generated * descriptors to the cluster. * * @param content The image to process. */ @Override protected void process(BufferedImage content) { DescribeImageDense<GrayU8, TupleDesc_F64> hog = HOGHelper.getHOGDescriptors(content); for (TupleDesc_F64 desc : hog.getDescriptions()) { this.cluster.addReference(desc); } }
Example #24
Source File: MaskGenerator.java From cineast with MIT License | 5 votes |
public static ArrayList<GrayU8> multiply3D(ArrayList<GrayU8> input, ArrayList<GrayU8> output, double value){ for (int i = 0; i < input.size(); ++i){ PixelMath.multiply(input.get(i), value, output.get(i)); } return output; }
Example #25
Source File: MaskGenerator.java From cineast with MIT License | 5 votes |
public static ArrayList<GrayU8> gaussianFilterSpatial(ArrayList<GrayU8> input, ArrayList<GrayU8> output, int spatialRadius){ for (int i = 0; i < input.size(); ++i){ GBlurImageOps.gaussian(input.get(i), output.get(i), -1, spatialRadius, null); } return output; }
Example #26
Source File: MaskGenerator.java From cineast with MIT License | 5 votes |
public static ArrayList<GrayU8> gaussianFilter3D(ArrayList<GrayU8> input, ArrayList<GrayU8> output, int spatialRadius, int temporalRadius) { ArrayList<GrayU8> spatialResult = createNewMasks(input); gaussianFilterSpatial(input, spatialResult, spatialRadius); gaussianFilterTemporal(spatialResult, output, temporalRadius); return output; }
Example #27
Source File: HOG.java From cineast with MIT License | 5 votes |
/** * This method represents the first step that's executed when processing query. The associated SegmentContainer is examined and feature-vectors are being generated. The generated vectors are returned by this method together with an optional weight-vector. * <p> * <strong>Important: </strong> The weight-vector must have the same size as the feature-vectors returned by the method. * * @param sc SegmentContainer that was submitted to the feature module. * @param qc A QueryConfig object that contains query-related configuration parameters. Can still be edited. * @return List of feature vectors for lookup. */ @Override protected List<float[]> preprocessQuery(SegmentContainer sc, ReadableQueryConfig qc) { /* Prepare feature pair. */ List<float[]> features = new ArrayList<>(1); /* Extract features. */ BufferedImage image = sc.getMostRepresentativeFrame().getImage().getBufferedImage(); DescribeImageDense<GrayU8, TupleDesc_F64> hog = HOGHelper.getHOGDescriptors(image); if (hog != null && hog.getDescriptions().size() > 0) { features.add(this.histogram(true, hog.getDescriptions())); } return features; }
Example #28
Source File: MaskGenerator.java From cineast with MIT License | 5 votes |
public static ImageRectangle getLargestBoundingBox(GrayU8 mask){ List<ImageRectangle> rects = getBoundingBox(mask); ImageRectangle largest = new ImageRectangle(0,0,0,0); for(ImageRectangle rect : rects){ if(rect.getWidth() * rect.getHeight() > largest.getWidth() * largest.getHeight()){ largest = rect; } } return largest; }
Example #29
Source File: MotionDetectorController.java From Telephoto with Apache License 2.0 | 4 votes |
private boolean detect(ImageShot shot) { if (shot != null && shot.getParameters() != null && shot.getImage() != null) { long start = System.currentTimeMillis(); byte[] image = shot.getImage(); int width = shot.getParameters().getPreviewSize().width; int height = shot.getParameters().getPreviewSize().height; GrayU8 greyImage = new GrayU8(width, height); ConvertYV12.yu12ToGray(image, width, height, greyImage); GrayU8 segmented = motionDetector.addImage(greyImage, matrix); saveProcessingTime(System.currentTimeMillis() - start); if (segmented != null && oldShot != null) { long timeFromLast = System.currentTimeMillis() - PrefsController.instance.getLastMdDetected(); // Первое движение за долгое время! boolean rareMotion = timeFromLast > 1000 * 60 * 60; if (MdSwitchType.ON == mdType || rareMotion) { Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); VisualizeImageData.binaryToBitmap(segmented, false, bitmap, null); final ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); List<ImageShot> oldShotsCopy = new ArrayList<>(); oldShotsCopy.addAll(oldShots); listener.motionDetected( stream.toByteArray(), shot.toYuvByteArray(), oldShot.toYuvByteArray(), rareMotion, oldShotsCopy); } else { L.i("Motion detected, but not sent, because time from last motion: " + timeFromLast); } PrefsController.instance.updateLastMdDetected(); } oldShot = shot; oldShots.addLast(shot); if (oldShots.size() > IMAGE_HISTORY_SIZE) { oldShots.removeFirst(); } return true; } else { L.i("Motion detector got null photo!"); oldShot = null; oldShots.clear(); return false; } }
Example #30
Source File: EdgeList.java From cineast with MIT License | 4 votes |
@Override public CannyEdge<GrayU8, GrayS16> load(Thread arg0) { return FactoryEdgeDetectors.canny(2, true, true, GrayU8.class, GrayS16.class); }