Click here to Skip to main content
15,114,127 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I want to do a contrast stretch program to enhancement my image. I split the image into 3 channels (red, green, blue) but I don't know how to update the value of these channels. I don't know how to work with two dimension arrays. I have error ("cannot implicitly convert type int to byte")

What I have tried:

private void button1_Click(object sender, EventArgs e)
       {

           int[] maxAndMin = GetMaxMin(bmp);
               for (int i = 0; i < w; i++)
               {
                   for (int j = 0; j < h; j++)
                   {

                       red[i, j] = ((red[i, j] - maxAndMin[1]) * 255 / (maxAndMin[0] - maxAndMin[1]));
                       green [i, j] = ((green [i, j] - maxAndMin[1]) * 255 / (maxAndMin[0] - maxAndMin[1]));
                       blue[i, j] = ((blue[i, j] - maxAndMin[1]) * 255 / (maxAndMin[0] - maxAndMin[1]));

                   }
               }

               int[] histored = new int[256];
               int[] histogreen = new int[256];
               int[] histoblue = new int[256];
               histogram(w, h, red, ref histored);
               histogram(w, h, green, ref histogreen);
               histogram(w, h, blue, ref histoblue);
Posted
Updated 23-May-19 23:57pm
Comments
lmoelleb 24-May-19 2:09am
   
Include details on which line the error is on - please do not waste our time by not providing readily available information provided straight from the compiler giving you the error. Also please change the title to match what you are asking. You are NOT asking how to do contrast stretching of an image. You are just stating you get an error (and I assume, would like help on that?)
TheRealSteveJudge 24-May-19 7:29am
   
Thank you for accepting my answer! I hope my answer did not insult you as it was assumed by Bill. If that is the case I would like to apologise.

A lot of code missing ... hard to tell what you are doing. See if this is helpful: [^]
   
Why don't you use one of the available free image processing libraries instead of wasting your and our precious time?

e.g. An open-source solution for on-the-fly processing of images using .NET :: ImageProcessor[^]

Changing contrast ist described here
Contrast :: ImageProcessor[^]
   
Comments
BillWoodruff 24-May-19 4:53am
   
My vote of #1

"instead of wasting your and our precious time?"

If a post makes you angry, then don't respond. There's no reason to insult the OP here. This is not an unreasonable question, and there's nothing wrong with someone exploring how to process images.
TheRealSteveJudge 24-May-19 5:12am
   
Thank you Bill. It was not my intention to insult the OP.
My intention was to give the OP some useful resource in order to easily do the constrast adjustment instead of self developping image manipulation stuff thus saving time. Maybe you got up on the wrong side of the bed today.
Nevertheless have a nice weekend!
BillWoodruff 24-May-19 5:17am
   
If you don't see how your language was insulting, I pity you.
Member 14129828 24-May-19 7:35am
   
thank you for your advice, I don't know about this library because I am a beginner in c# ... can you give me more link to help me for understanding the library and how to load it in my project if you don't mind
TheRealSteveJudge 24-May-19 7:44am
   
This is what I found:

A quick introduction:
https://naimhamadi.wordpress.com/2014/06/25/processing-images-in-c-easily-using-imageprocessor/

This here features 30 examples:
https://csharp.hotexamples.com/examples/ImageProcessor/ImageFactory/-/php-imagefactory-class-examples.html

I hope this will be helpful.
Member 14129828 24-May-19 7:57am
   
Thank you very much ... This information is very valuable to me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900