Esempio n. 1
0
        Camera(Camera* camera, UInt32 alias_num) 
	{
		if (alias_num >= camera.aliases.size())

            ThrowCME("Camera: Internal error, alias number out of range specified.");

        make = camera.make;
		model = camera.aliases[alias_num];
		canonical_make = camera.canonical_make;
		canonical_model = camera.canonical_model;
		canonical_alias = camera.canonical_aliases[alias_num];
		canonical_id = camera.canonical_id;
		mode = camera.mode;
		cfa = camera.cfa;
		supported = camera.supported;
		cropSize = camera.cropSize;
		cropPos = camera.cropPos;
		decoderVersion = camera.decoderVersion;
		for (UInt32 i = 0; i<camera.blackAreas.size(); i++) {
			blackAreas.push_back(camera.blackAreas[i]);
		}
		for (UInt32 i = 0; i<camera.sensorInfo.size(); i++) {
			sensorInfo.push_back(camera.sensorInfo[i]);
		}
map<string, string>::const_iterator mi = camera.hints.begin();
		for (; mi != camera.hints.end(); ++mi) {
			hints.insert(make_pair((* mi).first, (* mi).second));
		}
	}
Esempio n. 2
0
        protected override void DemosaickingAdams(ImageComponent <ushort> image, ColorFilterArray cfa)
        {
            SuperSimple(image, cfa);
            // Interpolate the green channel by bilinear on the boundaries
            // make the average of four neighbouring green pixels: Nourth, South, East, West

            /* Parallel.For(0, image.dim.Height, row =>
             * {
             *   var cfapos = (row % 2) * 2;
             *   var posRow = row * image.dim.Width;
             *
             *   long gn = 1, gs;
             *   if (row > 0) gn = row - 1;
             *   if (row < image.dim.Height - 1) gs = row + 1; else gs = image.dim.Height - 2;
             *   gs *= image.dim.Width;
             *   gn *= image.dim.Width;
             *
             *   for (long col = 0; col < image.dim.Width; col++)
             *   {
             *       var pos = posRow + col;
             *       var color = mask[pos] = cfa.cfa[cfapos + (col % 2)];
             *       long gw = 1, ge;
             *       if (col < image.dim.Width - 1) ge = col + 1; else ge = image.dim.Width - 2;
             *       if (col > 0) gw = col - 1;
             *
             *       if ((color != CFAColor.Green))
             *       {
             *           //interpolate green
             *           image.green[pos] = (ushort)((image.green[gn + col] + image.green[gs + col] + image.green[posRow + gw] + image.green[posRow + ge]) / 4);
             *       }
             *   }
             * });*/
        }
Esempio n. 3
0
        Camera(pugi::xml_node &camera)
        {
            cfa = newiPoint2D(0, 0);
            pugi::xml_attribute key = camera.attribute("make");
            if (!key)

                ThrowCME("Camera XML Parser: \"make\" attribute not found.");
            make = canonical_make = key.as_string();

            key = camera.attribute("model");
            if (!key)

                ThrowCME("Camera XML Parser: \"model\" attribute not found.");
            model = canonical_model = canonical_alias = key.as_string();

            canonical_id = make + " " + model;

            supported = true;
            key = camera.attribute("supported");
            if (key)
            {
                string s = string(key.as_string());
                if (s.compare("no") == 0)
                    supported = false;
            }

            key = camera.attribute("mode");
            if (key)
            {
                mode = key.as_string();
            }
            else
            {
                mode = string("");
            }

            key = camera.attribute("decoder_version");
            if (key)
            {
                decoderVersion = key.as_int(0);
            }
            else
            {
                decoderVersion = 0;
            }

            for (xml_node node = camera.first_child(); node; node = node.next_sibling())
            {

                parseCameraChild(node);
            }
        }
Esempio n. 4
0
        public RawImageData(iPoint2D _dim, UInt32 _bpc, UInt32 _cpp)
        {

            dim = (_dim); isCFA = (_cpp == 1); cfa = (new iPoint2D(0, 0));
            blackLevel = (-1); whitePoint = (65536);
            cpp = (_cpp); bpp = (_bpc * _cpp);
            blackLevelSeparate[0] = blackLevelSeparate[1] = blackLevelSeparate[2] = blackLevelSeparate[3] = -1;
            mBadPixelMap = null;
            mDitherScale = true;
            createData();
            pthread_mutex_init(&mymutex, null);
            pthread_mutex_init(&errMutex, null);
            pthread_mutex_init(&mBadPixelMutex, null);
        }
Esempio n. 5
0
        public RawImageData()
        {

            dim = new iPoint2D(0, 0);
            isCFA = (true);
            cfa = (new iPoint2D(0, 0));
            blackLevel = (-1);
            whitePoint = (65536);
            blackLevelSeparate[0] = blackLevelSeparate[1] = blackLevelSeparate[2] = blackLevelSeparate[3] = -1;
            pthread_mutex_init(&mymutex, null);
            mBadPixelMap = null;
            pthread_mutex_init(&errMutex, null);
            pthread_mutex_init(&mBadPixelMutex, null);
            mDitherScale = true;
        }
Esempio n. 6
0
        protected virtual void DemosaickingAdams(ImageComponent <ushort> image, ColorFilterArray cfa)
        {
            // Interpolate the green channel by bilinear on the boundaries
            // make the average of four neighbouring green pixels: Nourth, South, East, West
            Parallel.For(0, image.dim.height, row =>
            {
                for (long col = 0; col < image.dim.width; col++)
                {
                    var color = mask[row * image.dim.width + col];


                    //take the pixel and put it around
                    if (color == CFAColor.Green)
                    {
                        Interpolate(CFAColor.Green, image.green, col, row, image.dim);
                    }
                    else if (color == CFAColor.Red)
                    {
                        Interpolate(CFAColor.Red, image.red, col, row, image.dim);
                    }
                    else
                    {
                        Interpolate(CFAColor.Blue, image.blue, col, row, image.dim);
                    }

                    /*if (!(col < 3 || row < 3 || col >= image.dim.width - 3 || row >= image.dim.height - 3))
                     * {
                     *  //skip to the end of line to reduce calculation
                     *  col = image.dim.width - 4;
                     * }
                     * else if (((mask[row * image.dim.width + col] = cfa.cfa[((row % cfa.Size.width) * cfa.Size.height) + (col % cfa.Size.height)]) != CFAColor.Green))
                     * {
                     *  long gn, gs, ge, gw;
                     *  if (row > 0) gn = row - 1; else gn = 1;
                     *  if (row < image.dim.height - 1) gs = row + 1; else gs = image.dim.height - 2;
                     *  if (col < image.dim.width - 1) ge = col + 1; else ge = image.dim.width - 2;
                     *  if (col > 0) gw = col - 1; else gw = 1;
                     *
                     *  image.green[row * image.dim.width + col] = (ushort)((
                     *      image.green[gn * image.dim.width + col] +
                     *      image.green[gs * image.dim.width + col] +
                     *      image.green[row * image.dim.width + gw] +
                     *      image.green[row * image.dim.width + ge]) / 4.0);
                     * }*/
                }
            });
        }
Esempio n. 7
0
        protected virtual void DemosaickingAdams(ImageComponent <ushort> image, ColorFilterArray cfa)
        {
            // Interpolate the green channel by bilinear on the boundaries
            // make the average of four neighbouring green pixels: Nourth, South, East, West
            Parallel.For(0, image.dim.height, row =>
            {
                for (long col = 0; col < image.dim.width; col++)
                {
                    if (!(col < 3 || row < 3 || col >= image.dim.width - 3 || row >= image.dim.height - 3))
                    {
                        //skip to the end of line to reduce calculation
                        col = image.dim.width - 4;
                    }
                    else if (((mask[row * image.dim.width + col] = cfa.cfa[((row % 2) * 2) + (col % 2)]) != CFAColor.Green))
                    {
                        long gn, gs, ge, gw;
                        if (row > 0)
                        {
                            gn = row - 1;
                        }
                        else
                        {
                            gn = 1;
                        }
                        if (row < image.dim.height - 1)
                        {
                            gs = row + 1;
                        }
                        else
                        {
                            gs = image.dim.height - 2;
                        }
                        if (col < image.dim.width - 1)
                        {
                            ge = col + 1;
                        }
                        else
                        {
                            ge = image.dim.width - 2;
                        }
                        if (col > 0)
                        {
                            gw = col - 1;
                        }
                        else
                        {
                            gw = 1;
                        }

                        image.green[row * image.dim.width + col] = (ushort)((
                                                                                image.green[gn * image.dim.width + col] +
                                                                                image.green[gs * image.dim.width + col] +
                                                                                image.green[row * image.dim.width + gw] +
                                                                                image.green[row * image.dim.width + ge]) / 4.0);
                    }
                }
            });

            // Interpolate the green by Adams algorithm inside the image
            // First interpolate green directionally
            Parallel.For(3, image.dim.height - 3, row =>
            {
                for (int col = 3; col < image.dim.width - 3; col++)
                {
                    if (((mask[row * image.dim.width + col] = cfa.cfa[((row % 2) * 2) + (col % 2)]) != CFAColor.Green))
                    {
                        long l   = row * image.dim.width + col;
                        long lp1 = (row + 1) * image.dim.width + col;
                        long lp2 = (row + 2) * image.dim.width + col;
                        long lm1 = (row - 1) * image.dim.width + col;
                        long lm2 = (row - 2) * image.dim.width + col;

                        // Compute vertical and horizontal gradients in the green channel
                        double adv = Math.Abs(image.green[lp1] - image.green[lm1]);
                        double adh = Math.Abs(image.green[l - 1] - image.green[l + 1]);
                        double dh0, dv0;

                        // If current pixel is blue, we compute the horizontal and vertical blue second derivatives
                        // else is red, we compute the horizontal and vertical red second derivatives
                        if (mask[l] == CFAColor.Blue)
                        {
                            dh0 = 2.0 * image.blue[l] - image.blue[l + 2] - image.blue[l - 2];
                            dv0 = 2.0 * image.blue[l] - image.blue[lp2] - image.blue[lm2];
                        }
                        else
                        {
                            dh0 = 2.0 * image.red[l] - image.red[l + 2] - image.red[l - 2];
                            dv0 = 2.0 * image.red[l] - image.red[lp2] - image.red[lm2];
                        }

                        // Add vertical and horizontal differences
                        adh        = adh + Math.Abs(dh0);
                        adv        = adv + Math.Abs(dv0);
                        double val = 0;
                        if (Math.Abs(adv - adh) < threshold)
                        {
                            // If vertical and horizontal differences are similar, compute an isotropic average
                            val = (image.green[lm1] + image.green[lp1] + image.green[l - 1] + image.green[l + 1]) / 4.0 + (dh0 + dv0) / 8.0;
                        }
                        else if (adh < adv)
                        {
                            // Else If horizontal differences are smaller, compute horizontal average
                            val = (image.green[l - 1] + image.green[l + 1]) / 2.0 + (dh0) / 4.0;
                        }
                        else if (adv < adh)
                        {
                            // Else If vertical differences are smaller, compute vertical average
                            val = (image.green[lp1] + image.green[lm1]) / 2.0 + (dv0) / 4.0;
                        }

                        if (val < 0)
                        {
                            val = 0;
                        }
                        image.green[l] = (ushort)(val);
                    }
                }
            });
        }
Esempio n. 8
0
        protected void SuperSimple(ImageComponent <ushort> image, ColorFilterArray cfa)
        {
            // Interpolate the green channel by bilinear on the boundaries
            // make the average of four neighbouring green pixels: Nourth, South, East, West
            Parallel.For(0, image.dim.height, row =>
            {
                var cfapos = (row % cfa.Size.height) * cfa.Size.width;
                var posRow = row * image.dim.width;

                long gn = 1, gs;
                if (row > 0)
                {
                    gn = row - 1;
                }
                if (row < image.dim.height - 1)
                {
                    gs = row + 1;
                }
                else
                {
                    gs = image.dim.height - 2;
                }
                gs *= image.dim.width;
                gn *= image.dim.width;

                for (long col = 0; col < image.dim.width; col++)
                {
                    var pos   = posRow + col;
                    var color = cfa.cfa[cfapos + (col % cfa.Size.width)];
                    long gw   = 1, ge;
                    if (col < image.dim.width - 1)
                    {
                        ge = col + 1;
                    }
                    else
                    {
                        ge = image.dim.width - 2;
                    }
                    if (col > 0)
                    {
                        gw = col - 1;
                    }

                    if ((color != CFAColor.Green))
                    {
                        //interpolate green
                        image.green[pos] = (ushort)((image.green[gn + col] + image.green[gs + col] + image.green[posRow + gw] + image.green[posRow + ge]) / 4);
                        if (color == CFAColor.Red)
                        {
                            image.blue[pos] = (ushort)((image.blue[gn + ge] + image.blue[gn + gw] + image.blue[gs + ge] + image.blue[gs + gw]) / 4);
                        }
                        else
                        {
                            image.red[pos] = (ushort)((image.red[gn + ge] + image.red[gn + gw] + image.red[gs + ge] + image.red[gs + gw]) / 4);
                        }
                    }
                    else
                    {
                        if (row % 2 == bluey)
                        {
                            image.blue[pos] = (ushort)((image.blue[posRow + ge] + image.blue[posRow + gw]) / 2);
                            image.red[pos]  = (ushort)((image.red[gn + col] + image.red[gs + col]) / 2);
                        }
                        else
                        {
                            image.blue[pos] = (ushort)((image.blue[gn + col] + image.blue[gs + col]) / 2);
                            image.red[pos]  = (ushort)((image.red[posRow + ge] + image.red[posRow + gw]) / 2);
                        }
                    }
                }
            });
        }