What is a better way to read an image in a downsampling way, and then get
the brightness value based on each pixel's RGB values?


Right now, I am using BitmapFactory.loadFile with the option to set the
downsampling ratio.


Then I use two loops

for (int y = 0; y < height; y++) {

for (int x = 0; x < width; x++) {


to read each pixle's RGB value, and get the largest component as the
brightness value.

I save the brightness value in a byte[] array.


It takes about 1sec.

Where can I do to improve the speed?


I think Java loops should have similar computation speed as the C++ loops.
And BitmapFactory.loadFile should be fine. Then seems no way to improve it?
Or I may take a smaller size of photo.


Any light?


Thanks.

--

Search Discussions

  • Alexander Smorkalov at Dec 18, 2012 at 7:17 am
    Hello Linda Li,

    You can use color conversions from OpenCV Java API. You can convert rgba
    frame to gray scale by function Imgproc.cvtColor(mRgba, mGray,
    Imgproc.COLOR_RGBA2GRAY). It is the preferred way for most CV algorithms.

    --
  • Linda Li at Dec 19, 2012 at 7:21 am
    Thanks.
    RGBA2Gray in OpenCV is to use weighted average of RGB values.
    I need another expression of brightness values, which is the largest
    component among the RGB values.
    See wiki, there are different definitions of brightness. I prefer the one I
    mentioned.

    On Tuesday, December 18, 2012 1:17:56 AM UTC-6, Alexander Smorkalov wrote:

    Hello Linda Li,

    You can use color conversions from OpenCV Java API. You can convert rgba
    frame to gray scale by function Imgproc.cvtColor(mRgba, mGray,
    Imgproc.COLOR_RGBA2GRAY). It is the preferred way for most CV algorithms.
    --
  • Andrey Pavlenko at Dec 18, 2012 at 8:21 am
    Mat imread(const string& filename, int flags=1);
    function can automatically convert the image to gray-scale when the
    `CV_LOAD_IMAGE_GRAYSCALE` flag is specified;
    see
    http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#imread

    as for downscaling - you can call
    void resize(InputArray src, OutputArray dst, Size dsize, double fx=0, doublefy
    =0, int interpolation=INTER_LINEAR )<http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#resize>
    see
    http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#resize

    --
  • Linda Li at Dec 19, 2012 at 7:22 am
    I can not read the whole image into the memory of the Android phone,
    because it is too big.
    So the resize must be implemented in reading. And right now I use
    BitmapFactory downsampling way.

    Thanks.
    On Tuesday, December 18, 2012 2:21:34 AM UTC-6, Andrey Pavlenko wrote:

    Mat imread(const string& filename, int flags=1);
    function can automatically convert the image to gray-scale when the
    `CV_LOAD_IMAGE_GRAYSCALE` flag is specified;
    see
    http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#imread

    as for downscaling - you can call
    void resize(InputArray src, OutputArray dst, Size dsize, double fx=0,
    double fy=0, int interpolation=INTER_LINEAR )<http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#resize>
    see
    http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#resize
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupandroid-opencv @
categoriesandroid
postedDec 18, '12 at 7:01a
activeDec 19, '12 at 7:22a
posts5
users3
websiteandroid.com

People

Translate

site design / logo © 2017 Grokbase