English 中文(简体)
视窗电话中的侵蚀和隔ation?
原标题:Erosion and Dilation in Windows phone???

i 试图在我的视窗电话附录中应用电离和电离算法:

但很难做到: i 仅举一例调查,见http://channel9.msdn.com/coding4fun/articles/FaceLight-Silverlight-4-Real-time-Face-Detection”rel=“nofollow noreferer”http://channel9.msdn.com/coding4fun/articles/FaceLight-Silverlight-4-Real-time-Face-Detection。

FaceLight for Silverlight.

Is a very good example and that have Erode and Dilate algorithms , but my app have some differences , FaceLight take a picture from camera and I want my app load some image from Gallery and apply that algorithms.

I follow this steps 1.- Load the image from gallery.

PhotoChooserTask photo = new PhotoChooserTask();
        photo.Completed += (s, ee) =>
        {



            BitmapImage image = new BitmapImage();

            image.SetSource(ee.ChosenPhoto);

            image.CreateOptions = BitmapCreateOptions.None;

            this.imgoriginal.Source = image;

            GrayTimer.Start();



        };

        photo.Show();

2. 图像从直观图像中获取。

 WriteableBitmap grayimg = Operations.doGray(imgoriginal); // get the grayscale image 

        BitmapImage imggray = new BitmapImage();

        stream = new MemoryStream(grayimg.ToByteArray()); // get the array of the image

        this.Dispatcher.BeginInvoke(() =>
        {
            grayimg.SaveJpeg(stream, 320, 240, 0, 90); // resize and set quality
            imggray.SetSource(stream);
            grayImage.Source = imggray;// set the grayscale image in the control.
        });

这种方法

  public static WriteableBitmap doGray(Image image)
    {
        WriteableBitmap bitmap = new WriteableBitmap(image, null);
        for (int y = 0; y < bitmap.PixelHeight; y++)
        {
            for (int x = 0; x < bitmap.PixelWidth; x++)
            {
                int pixelLocation = bitmap.PixelWidth * y + x;
                int pixel = bitmap.Pixels[pixelLocation];
                byte[] pixelbytes = BitConverter.GetBytes(pixel);
                byte bwPixel = (byte)(.299 * pixelbytes[2] + .587 * pixelbytes[1] + .114 * pixelbytes[0]);
                pixelbytes[0] = bwPixel;
                pixelbytes[1] = bwPixel;
                pixelbytes[2] = bwPixel;
                bitmap.Pixels[pixelLocation] = BitConverter.ToInt32(pixelbytes, 0);
            }
        }

        return bitmap;
    }

所有工作罚款。

“原件图像”/

“GrayScale

现在,我采用Erode Algorithm。

WriteableBitmap g;

        BitmapImage imggray = new BitmapImage();

        imggray =(BitmapImage) grayImage.Source; // get the gray image from the Control.


        g = new WriteableBitmap(imggray);

        // i apply 3 times for try to see something :S
        er = Operations.Erode(g);
        for (int i = 1; i <= 2; i++)
        {
            Stream str = new MemoryStream(er.ToByteArray());
            BitmapImage r = new BitmapImage();
            WriteableBitmap n;
            er.SaveJpeg(str, 320, 240,0, 100);
            r.SetSource(str);
            n = new WriteableBitmap(r);
            er = Operations.Erode(n);

        }

        this.Dispatcher.BeginInvoke(() =>
        {
            stream = new MemoryStream(er.ToByteArray());
            BitmapImage result = new BitmapImage();
            er.SaveJpeg(stream, 320, 240, 0, 100);
            result.SetSource(stream);
            imgerode.Source = result;
        });

此处为埃尔德算法。

// Process method of the Erode5x5Filter class
    public static WriteableBitmap Erode(WriteableBitmap input)
    {
        var p = input.Pixels;
        var w = input.PixelWidth;
        var h = input.PixelHeight;
        var result = new WriteableBitmap(w, h);
        var rp = result.Pixels;
        var empty = 0; // = 0
        int c, cm;
        int i = 0;

        // Erode every pixel
        for (int y = 0; y < h; y++)
        {
            for (int x = 0; x < w; x++, i++)
            {
                // Middle pixel
                cm = p[y * w + x];
                if (cm == empty) { continue; }

                // Row 0
                // Left pixel
                if (x - 2 > 0 && y - 2 > 0)
                {
                    c = p[(y - 2) * w + (x - 2)];
                    if (c == empty) { continue; }
                }
                // Middle left pixel
                if (x - 1 > 0 && y - 2 > 0)
                {
                    c = p[(y - 2) * w + (x - 1)];
                    if (c == empty) { continue; }
                }
                if (y - 2 > 0)
                {
                    c = p[(y - 2) * w + x];
                    if (c == empty) { continue; }
                }
                if (x + 1 < w && y - 2 > 0)
                {
                    c = p[(y - 2) * w + (x + 1)];
                    if (c == empty) { continue; }
                }
                if (x + 2 < w && y - 2 > 0)
                {
                    c = p[(y - 2) * w + (x + 2)];
                    if (c == empty) { continue; }
                }

                // Row 1
                // Left pixel
                if (x - 2 > 0 && y - 1 > 0)
                {
                    c = p[(y - 1) * w + (x - 2)];
                    if (c == empty) { continue; }
                }


                // ... 
                // ... Process the rest of the 24 neighboring pixels
                // ...


                // If all neighboring pixels are processed 
                // it s clear that the current pixel is not a boundary pixel.
                rp[i] = cm;
            }
        }

        return result;
    }

这里是结果:没有发生:

“Erosiontext”/

and the same issue with Dilate algorithm but the result image is a blank image . Any ideas o suggestions?? I need help please.

问题回答

我很快看着你的侵蚀方法。 为什么不给你写信(实际上为两例从2到2级的住宿)来处理你试图处理的25起案件?

Although the Erode function looks like it should work on grayscale, have you tried thresholding your image to a binary mask (e.g. rp = p > 127 ? 255 : 0) before calling erode?

你在座的《刑法》也从未修改过<代码>i,从0.





相关问题
Silverlight Rich text box control

Our team decided that we need our own custom Rich text box control for Silverlight app we are developing. We looked at existing controls mentioned at A good rich text control for Silverlight but ...

Silverlight ImageBrush not rendering (with Bing Map Control)

I m trying to add an image to a Pushpin instance from the Silverlight Bing Map Control, but I can t seem to get it to render (the pushpin renders fine). This is probably a general WPF question rather ...

Silverlight OpenFileDialog DoEvents equivalent

I m processing large files after they are selected by the user. My code looks like the following: if (FileDialog.ShowDialog() == true) { // process really big file } This freezes up the UI so ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Silverlight, Updating the UI during processing

I have a simple silverlight multifile upload application, and i want to provide the user with some feedback, right now its only in a test phase and i dont have the webservice. Somehow i cant get the ...

Silverlight 3 - FindName returns null

This looks a bug to me.. Using Silverlight 3 and i have a user control defined in XAML and trying to access the object during runtime returns a null. <Grid> <common:CommonGridEditPanel x:...

silverlight 3 collection binding

Someone please help me understand why this binding does not work... I have a class called SelectionManager with a property called dates which is populated by a WCF service. The property is an ...

热门标签