(no subject)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

(no subject)

Marijonas Tutkus
Hello,

I was looking at the code of image background subtraction and there I have found this piece of code:


        ImageProcessor background = new ByteProcessor(width, height);
        byte[] backgroundpixels = (byte[])background.getPixels();

Could anyone, please, explain me a meaning of second line?


Marijonas
Reply | Threaded
Open this post in threaded view
|

(no subject)

Rob van 't Hof
Hi,
The second line gives you the pixels as a 1-dimensional array. You can
then access pixels values in  simple for-next loop such as:

         byte[] backgroundpixels = (byte[])background.getPixels();
         PixelCount = backgroundpixels .getPixelCount();

         for (x = 0; x < PixelCount; x++) {
             pixVal = backgroundpixels [x];
             if (pixVal == 0) {
                 backgroundpixels [x] = (byte) 0xff; //set pixel value
to "255"
             } else {
                 backgroundpixels [x] = 0; //set pixel value to "0"
             }
         }

This kind of pixel access is a lot faster than things like getpixel();


hope that helps,
Rob


On 14/02/2012 14:00, Marijonas Tutkus wrote:

> Hello,
>
> I was looking at the code of image background subtraction and there I have found this piece of code:
>
>
>          ImageProcessor background = new ByteProcessor(width, height);
>          byte[] backgroundpixels = (byte[])background.getPixels();
>
> Could anyone, please, explain me a meaning of second line?
>
>
> Marijonas
>

--
_____________________________
Dr. Rob van 't Hof
Senior Lecturer

Centre for Molecular Medicine
MRC IGMM
University of Edinburgh
Western General Hospital
Crewe Road, Edinburgh EH4 2XU
United Kingdom


Phone: (+44)-131-6511031
email: [hidden email]
_____________________________



The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.