31
31
* <p>At present, only RGB images are supported, and the A channel is always ignored.
32
32
*
33
33
* <p>Details of data storage: a {@link TensorImage} object may have 2 potential sources of truth: a
34
- * {@link Bitmap} or a {@link TensorBuffer}. {@link TensorImage} maintains the state and only
35
- * converts one to the other when needed. A typical use case of {@link TensorImage} is to first load
36
- * a {@link Bitmap} image, then process it using {@link ImageProcessor}, and finally get the
37
- * underlying {@link ByteBuffer} of the {@link TensorBuffer} and feed it into the TFLite
38
- * interpreter.
34
+ * {@link android.graphics. Bitmap} or a {@link TensorBuffer}. {@link TensorImage} maintains the
35
+ * state and only converts one to the other when needed. A typical use case of {@link TensorImage}
36
+ * is to first load a {@link android.graphics. Bitmap} image, then process it using {@link
37
+ * ImageProcessor}, and finally get the underlying {@link ByteBuffer} of the {@link TensorBuffer}
38
+ * and feed it into the TFLite interpreter.
39
39
*
40
40
* <p>IMPORTANT: to achieve the best performance, {@link TensorImage} avoids copying data whenever
41
41
* it's possible. Therefore, it doesn't own its data. Callers should not modify data objects those
42
- * are passed to {@link TensorImage#load(Bitmap)} or {@link TensorImage#load(TensorBuffer)}.
42
+ * are passed to {@link TensorImage#load(Bitmap)} or {@link TensorImage#load(TensorBuffer,
43
+ * ColorSpaceType)}.
43
44
*
44
45
* <p>IMPORTANT: all methods are not proved thread-safe.
45
46
*
@@ -87,10 +88,11 @@ public TensorImage(DataType dataType) {
87
88
}
88
89
89
90
/**
90
- * Initializes a {@link TensorImage} object of {@link DataType#UINT8} with a {@link Bitmap} .
91
+ * Initializes a {@link TensorImage} object of {@link DataType#UINT8} with a {@link
92
+ * android.graphics.Bitmap} .
91
93
*
92
- * @see TensorImage #load(Bitmap) for reusing the object when it's expensive to create objects
93
- * frequently, because every call of {@code fromBitmap} creates a new {@link TensorImage}.
94
+ * @see #load(Bitmap) for reusing the object when it's expensive to create objects frequently,
95
+ * because every call of {@code fromBitmap} creates a new {@link TensorImage}.
94
96
*/
95
97
public static TensorImage fromBitmap (Bitmap bitmap ) {
96
98
TensorImage image = new TensorImage ();
@@ -113,11 +115,12 @@ public static TensorImage createFrom(TensorImage src, DataType dataType) {
113
115
}
114
116
115
117
/**
116
- * Loads a {@link Bitmap} image object into this {@link TensorImage}.
118
+ * Loads a {@link android.graphics. Bitmap} image object into this {@link TensorImage}.
117
119
*
118
120
* <p>Note: if the {@link TensorImage} has data type other than {@link DataType#UINT8}, numeric
119
121
* casting and clamping will be applied when calling {@link #getTensorBuffer} and {@link
120
- * #getBuffer}, where the {@link Bitmap} will be converted into a {@link TensorBuffer}.
122
+ * #getBuffer}, where the {@link android.graphics.Bitmap} will be converted into a {@link
123
+ * TensorBuffer}.
121
124
*
122
125
* <p>Important: when loading a bitmap, DO NOT MODIFY the bitmap from the caller side anymore. The
123
126
* {@link TensorImage} object will rely on the bitmap. It will probably modify the bitmap as well.
@@ -183,9 +186,9 @@ public void load(TensorBuffer buffer) {
183
186
}
184
187
185
188
/**
186
- * Loads a {@link TensorBuffer} containing pixel values with the specific {@link ColorSapceType }.
189
+ * Loads a {@link TensorBuffer} containing pixel values with the specific {@link ColorSpaceType }.
187
190
*
188
- * <p>Only supports {@link ColorSapceType #RGB} and {@link ColorSpaceType#GRAYSCALE}. Use {@link
191
+ * <p>Only supports {@link ColorSpaceType #RGB} and {@link ColorSpaceType#GRAYSCALE}. Use {@link
189
192
* #load(TensorBuffer, ImageProperties)} for other color space types.
190
193
*
191
194
* <p>Note: if the data type of {@code buffer} does not match that of this {@link TensorImage},
@@ -196,7 +199,6 @@ public void load(TensorBuffer buffer) {
196
199
* (1, h, w, 3) for RGB images, and either (h, w) or (1, h, w) for GRAYSCALE images
197
200
* @throws IllegalArgumentException if the shape of buffer does not match the color space type, or
198
201
* if the color space type is not supported
199
- * @see ColorSpaceType#assertShape
200
202
*/
201
203
public void load (TensorBuffer buffer , ColorSpaceType colorSpaceType ) {
202
204
checkArgument (
@@ -241,22 +243,23 @@ public void load(ByteBuffer buffer, ImageProperties imageProperties) {
241
243
}
242
244
243
245
/**
244
- * Loads an {@link Image} object into this {@link TensorImage}.
246
+ * Loads an {@link android.media. Image} object into this {@link TensorImage}.
245
247
*
246
- * <p>The main usage of this method is to load an {@link Image} object as model input to the <a
247
- * href="TFLite Task
248
+ * <p>The main usage of this method is to load an {@link android.media. Image} object as model
249
+ * input to the <a href="TFLite Task
248
250
* Library">https://www.tensorflow.org/lite/inference_with_metadata/task_library/overview</a>.
249
- * {@link TensorImage} backed by {@link Image} is not supported by {#link ImageProcessor}.
251
+ * {@link TensorImage} backed by {@link android.media.Image} is not supported by {#link
252
+ * ImageProcessor}.
250
253
*
251
- * <p>* @throws IllegalArgumentException if the {@link ImageFormat} of {@code image} is not
252
- * YUV_420_888
254
+ * <p>* @throws IllegalArgumentException if the {@link android.graphics. ImageFormat} of {@code
255
+ * image} is not YUV_420_888
253
256
*/
254
257
public void load (Image image ) {
255
258
container = MediaImageContainer .create (image );
256
259
}
257
260
258
261
/**
259
- * Returns a {@link Bitmap} representation of this {@link TensorImage}.
262
+ * Returns a {@link android.graphics. Bitmap} representation of this {@link TensorImage}.
260
263
*
261
264
* <p>Numeric casting and clamping will be applied if the stored data is not uint8.
262
265
*
@@ -266,9 +269,9 @@ public void load(Image image) {
266
269
* <p>Important: it's only a reference. DO NOT MODIFY. We don't create a copy here for performance
267
270
* concern, but if modification is necessary, please make a copy.
268
271
*
269
- * @return a reference to a {@link Bitmap} in {@code ARGB_8888} config ("A" channel is always
270
- * opaque) or in {@code ALPHA_8}, depending on the {@link ColorSpaceType} of this {@link
271
- * TensorBuffer}.
272
+ * @return a reference to a {@link android.graphics. Bitmap} in {@code ARGB_8888} config ("A"
273
+ * channel is always opaque) or in {@code ALPHA_8}, depending on the {@link ColorSpaceType} of
274
+ * this {@link TensorBuffer}.
272
275
* @throws IllegalStateException if the {@link TensorImage} never loads data
273
276
*/
274
277
public Bitmap getBitmap () {
@@ -320,17 +323,18 @@ public TensorBuffer getTensorBuffer() {
320
323
}
321
324
322
325
/**
323
- * Returns an {@link Image} representation of this {@link TensorImage}.
326
+ * Returns an {@link android.media. Image} representation of this {@link TensorImage}.
324
327
*
325
- * <p>This method only works when the {@link TensorImage} is backed by an {@link Image}, meaning
326
- * you need to first load an {@link Image} through {@link TensorImage#load(Image)}.
328
+ * <p>This method only works when the {@link TensorImage} is backed by an {@link
329
+ * android.media.Image}, meaning you need to first load an {@link android.media.Image} through
330
+ * {@link #load(Image)}.
327
331
*
328
332
* <p>Important: it's only a reference. DO NOT MODIFY. We don't create a copy here for performance
329
333
* concern, but if modification is necessary, please make a copy.
330
334
*
331
- * @return a reference to a {@link Bitmap} in {@code ARGB_8888} config ("A" channel is always
332
- * opaque) or in {@code ALPHA_8}, depending on the {@link ColorSpaceType} of this {@link
333
- * TensorBuffer}.
335
+ * @return a reference to a {@link android.graphics. Bitmap} in {@code ARGB_8888} config ("A"
336
+ * channel is always opaque) or in {@code ALPHA_8}, depending on the {@link ColorSpaceType} of
337
+ * this {@link TensorBuffer}.
334
338
* @throws IllegalStateException if the {@link TensorImage} never loads data
335
339
*/
336
340
public Image getMediaImage () {
0 commit comments