Difference between revisions of "Example Dense Image Features"
From BoofCV
Jump to navigationJump to search (Created page with "Dense image features are image descriptors that are computed across the whole image. They can be computed very fast and are used in many detection/recognition tasks. Example C...") |
m |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Dense image features are image descriptors that are computed across the whole image. They can be computed very fast and are used in many detection/recognition tasks. | Dense image features are image descriptors that are computed across the whole image. They can be computed very fast and are used in many detection/recognition tasks. | ||
Example Code: | Example Code: | ||
* [https://github.com/lessthanoptimal/BoofCV/blob/v0. | * [https://github.com/lessthanoptimal/BoofCV/blob/v0.40/examples/src/boofcv/examples/features/ExampleDenseImageFeatures.java ExampleAssociatePoints.java] | ||
Concepts: | Concepts: | ||
* Feature Descriptors | * Feature Descriptors | ||
* Object Detection | * Object Detection | ||
See Examples: | |||
* [[Example_Scene_Classification|KNN Scene Classifier]] | |||
= Example Code = | = Example Code = | ||
Line 26: | Line 29: | ||
// Here's an example of how to use the high level interface. There are a variety of algorithms to choose from | // Here's an example of how to use the high level interface. There are a variety of algorithms to choose from | ||
// For much larger images you might need to shrink the image down or change the cell size to get good results. | // For much larger images you might need to shrink the image down or change the cell size to get good results. | ||
public static void HighLevel( GrayF32 input) { | public static void HighLevel( GrayF32 input ) { | ||
System.out.println("\n------------------- Dense High Level"); | System.out.println("\n------------------- Dense High Level"); | ||
DescribeImageDense<GrayF32,TupleDesc_F64> describer = FactoryDescribeImageDense. | DescribeImageDense<GrayF32, TupleDesc_F64> describer = FactoryDescribeImageDense. | ||
hog(new ConfigDenseHoG(),input.getImageType()); | hog(new ConfigDenseHoG(), input.getImageType()); | ||
// sift(new ConfigDenseSift(),GrayF32.class); | // sift(new ConfigDenseSift(),GrayF32.class); | ||
// surfFast(new ConfigDenseSurfFast(),GrayF32.class); | // surfFast(new ConfigDenseSurfFast(),GrayF32.class); | ||
Line 37: | Line 40: | ||
// print out part of the first few features | // print out part of the first few features | ||
System.out.println("Total Features = "+describer.getLocations().size()); | System.out.println("Total Features = " + describer.getLocations().size()); | ||
for (int i = 0; i < 5; i++) { | for (int i = 0; i < 5; i++) { | ||
Point2D_I32 p = describer.getLocations().get(i); | Point2D_I32 p = describer.getLocations().get(i); | ||
TupleDesc_F64 d = describer.getDescriptions().get(i); | TupleDesc_F64 d = describer.getDescriptions().get(i); | ||
System.out.printf("%3d %3d = [ %f %f %f %f\n",p.x,p.y,d. | System.out.printf("%3d %3d = [ %f %f %f %f\n", p.x, p.y, d.data[0], d.data[1], d.data[2], d.data[3]); | ||
// You would process the feature descriptor here | |||
} | } | ||
} | } | ||
Line 56: | Line 61: | ||
describer.process(); | describer.process(); | ||
// Let's print a few parameters because. They can be modified using the configuration class passed in | // Let's print a few parameters just because we can. They can be modified using the configuration class passed in | ||
System.out.println("\n------------------- HOG Low Level"); | System.out.println("\n------------------- HOG Low Level"); | ||
System.out.println("HOG pixels per cell "+describer.getPixelsPerCell()); | System.out.println("HOG pixels per cell " + describer.getPixelsPerCell()); | ||
System.out.println("HOG region width "+describer.getRegionWidthPixelX()); | System.out.println("HOG region width " + describer.getRegionWidthPixelX()); | ||
System.out.println("HOG region height "+describer.getRegionWidthPixelY()); | System.out.println("HOG region height " + describer.getRegionWidthPixelY()); | ||
System.out.println("HOG bins "+describer.getOrientationBins()); | System.out.println("HOG bins " + describer.getOrientationBins()); | ||
// go through all the cells in the image. If you only wanted to process part of the image it could be done here | // go through all the cells in the image. If you only wanted to process part of the image it could be done here | ||
// In the high level API the order of cells isn't specified and might be in some arbitrary order or in some | // In the high level API the order of cells isn't specified and might be in some arbitrary order or in some | ||
// cases might even skip regions depending on the implementation. HOG will | // cases might even skip regions depending on the implementation. HOG will always compute a cell | ||
// for ( int i = 0; i < describer.getCellRows(); i++ ) { | |||
// for (int j = 0; j < describer.getCellCols(); j++) { | |||
// DescribeDenseHogFastAlg.Cell c = describer.getCell(i,j); | |||
// } | |||
// } | |||
} | } | ||
public static void main(String[] args) { | public static void main( String[] args ) { | ||
BufferedImage buffered = UtilImageIO. | BufferedImage buffered = UtilImageIO.loadImageNotNull(UtilIO.pathExample("segment/berkeley_man.jpg")); | ||
GrayF32 input = ConvertBufferedImage.convertFrom(buffered,(GrayF32)null); | GrayF32 input = ConvertBufferedImage.convertFrom(buffered, (GrayF32)null); | ||
HighLevel(input); | HighLevel(input); | ||
LowLevelHOG(input); | LowLevelHOG(input); | ||
} | } | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 12:53, 17 January 2022
Dense image features are image descriptors that are computed across the whole image. They can be computed very fast and are used in many detection/recognition tasks. Example Code:
Concepts:
- Feature Descriptors
- Object Detection
See Examples:
Example Code
/**
* This example shows you how to compute dense image features. They are typically used for classification and
* recognition type tasks. They are very fast to compute and were considered state of the art until around 2012.
*
* This example doesn't really do anything useful. All it does is compute and print out the features for the sake
* of simplicity. A more flushed out example with a use case can be found in
* {@link boofcv.examples.recognition.ExampleClassifySceneKnn}.
*
* For a visualization of HOG features see https://youtu.be/qMTtdiujAtQ?t=437.
*
* @author Peter Abeles
*/
public class ExampleDenseImageFeatures {
// Here's an example of how to use the high level interface. There are a variety of algorithms to choose from
// For much larger images you might need to shrink the image down or change the cell size to get good results.
public static void HighLevel( GrayF32 input ) {
System.out.println("\n------------------- Dense High Level");
DescribeImageDense<GrayF32, TupleDesc_F64> describer = FactoryDescribeImageDense.
hog(new ConfigDenseHoG(), input.getImageType());
// sift(new ConfigDenseSift(),GrayF32.class);
// surfFast(new ConfigDenseSurfFast(),GrayF32.class);
// process the image and compute the dense image features
describer.process(input);
// print out part of the first few features
System.out.println("Total Features = " + describer.getLocations().size());
for (int i = 0; i < 5; i++) {
Point2D_I32 p = describer.getLocations().get(i);
TupleDesc_F64 d = describer.getDescriptions().get(i);
System.out.printf("%3d %3d = [ %f %f %f %f\n", p.x, p.y, d.data[0], d.data[1], d.data[2], d.data[3]);
// You would process the feature descriptor here
}
}
public static void LowLevelHOG( GrayF32 input ) {
DescribeDenseHogFastAlg<GrayF32> describer = FactoryDescribeImageDenseAlg.
hogFast(new ConfigDenseHoG(), ImageType.single(GrayF32.class));
// The low level API gives you access to more information about the image. You can explicitly traverse it
// by rows and columns, and access the histogram for a region. The histogram has an easy to understand
// physical meaning.
describer.setInput(input);
describer.process();
// Let's print a few parameters just because we can. They can be modified using the configuration class passed in
System.out.println("\n------------------- HOG Low Level");
System.out.println("HOG pixels per cell " + describer.getPixelsPerCell());
System.out.println("HOG region width " + describer.getRegionWidthPixelX());
System.out.println("HOG region height " + describer.getRegionWidthPixelY());
System.out.println("HOG bins " + describer.getOrientationBins());
// go through all the cells in the image. If you only wanted to process part of the image it could be done here
// In the high level API the order of cells isn't specified and might be in some arbitrary order or in some
// cases might even skip regions depending on the implementation. HOG will always compute a cell
// for ( int i = 0; i < describer.getCellRows(); i++ ) {
// for (int j = 0; j < describer.getCellCols(); j++) {
// DescribeDenseHogFastAlg.Cell c = describer.getCell(i,j);
// }
// }
}
public static void main( String[] args ) {
BufferedImage buffered = UtilImageIO.loadImageNotNull(UtilIO.pathExample("segment/berkeley_man.jpg"));
GrayF32 input = ConvertBufferedImage.convertFrom(buffered, (GrayF32)null);
HighLevel(input);
LowLevelHOG(input);
}
}