none
How to use methods for image processing RRS feed

  • Question

  • Hi, i am new with c#

    i created a class. It's name is filtreler. And i created a method in it which perfoms a filtering operation. I would like to call it from main function. But i don't know how should i call and return parameters.

    Here is my method

     public void meanfilter(Bitmap GirisResmi, Bitmap CikisResmi)
            {
    
    
                Color OkunanRenk;
    
    
                int ResimGenisligi = GirisResmi.Width;
                int ResimYuksekligi = GirisResmi.Height;
    
    
           //some arithmetic operations
    
    
                        CikisResmi.SetPixel(x, y, Color.FromArgb(ortalamaR, ortalamaG, ortalamaB));
    
    
                    }
                }
    
    
    
                return;
    
            }
    
    

    and my main function

     private void sliderKernel_MouseUp(object sender, MouseEventArgs e)
            {
                Filtreler f1 = new Filtreler();
                
                Bitmap GirisResmi = new Bitmap(pBox_SOURCE.Image);
                Bitmap CikisResmi= new Bitmap(GirisResmi.Width, GirisResmi.Height);
    
                //    CikisResmi = new Bitmap(pBox_PROCESSED.Image); //cikis resmine resim al
                int SablonBoyutu = 5;
               
                f1.meanfilter(GirisResmi,CikisResmi);
              
                 }
    i don't know how to return image. Please help me

     
    Monday, July 22, 2019 11:55 AM

Answers

  • There is no need to "return" an image here.  Your code is modifying the CikisResmi parameter, which is bound to the CikisResmi bitmap in the mouseup handler.  The changes you make within the "meanfilter" function will be seen in the mouse up handler.  You just have to decide what to do with the modified bitmap.

    By the way, GetPixel and SetPixel are hopelessly slow.  To get any real performance, you will want to fetch the pixels as an integer array and manipulate them as arrays.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    • Marked as answer by MustafaUysal Wednesday, July 24, 2019 1:58 PM
    Tuesday, July 23, 2019 10:15 PM

All replies

  • Return what image? Nowhere in your `meanfilter` method do you do anything with an image other than what was passed in. Since (in your example) you are calling SetPixel on the second parameter you are modifying the argument that was passed to it (in your example `CikisResmi`. Therefore there is nothing to return as you've modify an argument that was passed in.

    Michael Taylor http://www.michaeltaylorp3.net

    Monday, July 22, 2019 1:50 PM
    Moderator
  • Hi MustafaUysal,

    Thank you for posting here.

    For your question, could you tell me what do you want to filter? Please describe it more clearly.

    If you want to return an image, you could try the following code to return an image.

     static Bitmap meanfilter(Bitmap b1,Bitmap b2)
            {
                //some operations
    
                return b1;
            }

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, July 23, 2019 1:41 AM
    Moderator
  • There is no need to "return" an image here.  Your code is modifying the CikisResmi parameter, which is bound to the CikisResmi bitmap in the mouseup handler.  The changes you make within the "meanfilter" function will be seen in the mouse up handler.  You just have to decide what to do with the modified bitmap.

    By the way, GetPixel and SetPixel are hopelessly slow.  To get any real performance, you will want to fetch the pixels as an integer array and manipulate them as arrays.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    • Marked as answer by MustafaUysal Wednesday, July 24, 2019 1:58 PM
    Tuesday, July 23, 2019 10:15 PM