Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Image Brightness

Image Brightness

Scheduled Pinned Locked Moved C#
adobeperformancehelptutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lexx_zone
    wrote on last edited by
    #1

    Hi guys! I have an image that I need to process. Actually I want to change brightness and contrast level. I tried to use a lot of algorithms and filters for processing such as AForge.Imaging.Filters, Color Matrix and many many others but no one can't provide a high processing performance. The main idea - to make a program which will allow to change brightness and contrast of the image in realtime by using TrackBar component like it realized in Adobe photoshop or in Windows Vista Photo Gallery in Photo Editing mode. The main problem - processing performance. For small size images Aforge filters works perfectly, but if I try to process the image which has been made by the 9.0Mpx digital camera, with resolution 3712x2088 it becomes a really big problem. Aforge brightness filter works too slow for big bitmaps. If anybody know how to resolve this problem, please help. I wish to know how brightness correction works in Vista Photo gallery... It can change brightness for any image with any size in realtime with incredible speed even if you will shake trackbar pointer side by side. How did they realized it??

    C L L 3 Replies Last reply
    0
    • L lexx_zone

      Hi guys! I have an image that I need to process. Actually I want to change brightness and contrast level. I tried to use a lot of algorithms and filters for processing such as AForge.Imaging.Filters, Color Matrix and many many others but no one can't provide a high processing performance. The main idea - to make a program which will allow to change brightness and contrast of the image in realtime by using TrackBar component like it realized in Adobe photoshop or in Windows Vista Photo Gallery in Photo Editing mode. The main problem - processing performance. For small size images Aforge filters works perfectly, but if I try to process the image which has been made by the 9.0Mpx digital camera, with resolution 3712x2088 it becomes a really big problem. Aforge brightness filter works too slow for big bitmaps. If anybody know how to resolve this problem, please help. I wish to know how brightness correction works in Vista Photo gallery... It can change brightness for any image with any size in realtime with incredible speed even if you will shake trackbar pointer side by side. How did they realized it??

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      The easiest way to do this is with a color matrix set for brightness and contrast changes. Fotovision ( the MS sample ) has examples Ultimately, those programs are faster b/c they are written in C, not C#

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      1 Reply Last reply
      0
      • L lexx_zone

        Hi guys! I have an image that I need to process. Actually I want to change brightness and contrast level. I tried to use a lot of algorithms and filters for processing such as AForge.Imaging.Filters, Color Matrix and many many others but no one can't provide a high processing performance. The main idea - to make a program which will allow to change brightness and contrast of the image in realtime by using TrackBar component like it realized in Adobe photoshop or in Windows Vista Photo Gallery in Photo Editing mode. The main problem - processing performance. For small size images Aforge filters works perfectly, but if I try to process the image which has been made by the 9.0Mpx digital camera, with resolution 3712x2088 it becomes a really big problem. Aforge brightness filter works too slow for big bitmaps. If anybody know how to resolve this problem, please help. I wish to know how brightness correction works in Vista Photo gallery... It can change brightness for any image with any size in realtime with incredible speed even if you will shake trackbar pointer side by side. How did they realized it??

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        How is that different from yesterday's post[^]? Pull this one again, and your brightness could become zero, as in blacklisted. :mad:

        Luc Pattyn [Forum Guidelines] [My Articles]


        The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


        1 Reply Last reply
        0
        • L lexx_zone

          Hi guys! I have an image that I need to process. Actually I want to change brightness and contrast level. I tried to use a lot of algorithms and filters for processing such as AForge.Imaging.Filters, Color Matrix and many many others but no one can't provide a high processing performance. The main idea - to make a program which will allow to change brightness and contrast of the image in realtime by using TrackBar component like it realized in Adobe photoshop or in Windows Vista Photo Gallery in Photo Editing mode. The main problem - processing performance. For small size images Aforge filters works perfectly, but if I try to process the image which has been made by the 9.0Mpx digital camera, with resolution 3712x2088 it becomes a really big problem. Aforge brightness filter works too slow for big bitmaps. If anybody know how to resolve this problem, please help. I wish to know how brightness correction works in Vista Photo gallery... It can change brightness for any image with any size in realtime with incredible speed even if you will shake trackbar pointer side by side. How did they realized it??

          L Offline
          L Offline
          lexx_zone
          wrote on last edited by
          #4

          I've found one cool algorithm for brightness and contrast's change.

          public static bool Brightness(Bitmap b, int nBrightness)
          {
          if (nBrightness < -255 || nBrightness > 255)
          return false;

          		// GDI+ still lies to us - the return format is BGR, NOT RGB.
          		BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
          
          		int stride = bmData.Stride;
          		System.IntPtr Scan0 = bmData.Scan0;
          
          		int nVal = 0;
          
          		unsafe
          		{
          			byte \* p = (byte \*)(void \*)Scan0;
          
          			int nOffset = stride - b.Width\*3;
          			int nWidth = b.Width \* 3;
          
          			for(int y=0;y<b.Height;++y)
          			{
          				for(int x=0; x < nWidth; ++x )
          				{
          					nVal = (int) (p\[0\] + nBrightness);
          	
          					if (nVal < 0) nVal = 0;
          					if (nVal > 255) nVal = 255;
          
          					p\[0\] = (byte)nVal;
          
          					++p;
          				}
          				p += nOffset;
          			}
          		}
          
          		b.UnlockBits(bmData);
          
          		return true;
          	}
          
          	public static bool Contrast(Bitmap b, sbyte nContrast)
          	{
          		if (nContrast < -100) return false;
          		if (nContrast >  100) return false;
          
          		double pixel = 0, contrast = (100.0+nContrast)/100.0;
          
          		contrast \*= contrast;
          
          		int red, green, blue;
          		
          		// GDI+ still lies to us - the return format is BGR, NOT RGB.
          		BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
          
          		int stride = bmData.Stride;
          		System.IntPtr Scan0 = bmData.Scan0;
          
          		unsafe
          		{
          			byte \* p = (byte \*)(void \*)Scan0;
          
          			int nOffset = stride - b.Width\*3;
          
          			for(int y=0;y<b.Height;++y)
          			{
          				for(int x=0; x < b.Width; ++x )
          				{
          					blue = p\[0\];
          					green = p\[1\];
          					red = p\[2\];
          			
          					pixel = red/255.0;
          					pixel -= 0.5;
          					pixel \*= contrast;
          					pixel += 0.5;
          					pixel \*= 255;
          					if (pixel < 0) pixel = 0;
          					if (pixel > 255) pixel = 255;
          					p\[2\] = (byte) pixel;
          
          					pixel = green/255.0;
          					pixel -= 0.5;
          					pixel \*= contrast;
          					pixel += 0.5;
          					pixel \*= 255;
          					if (pixel < 0) pixel = 0;
          					if (pixel > 255) pixel = 255;
          					p\[1\] = (byte) pixel;
          
          					pixel = blue/255.0;
          					pixel -= 0.5;
          					pixel \*= contrast;
          					pixel += 0.5;
          					pixel \*= 255;
          					if (pixel < 0) pixel = 0;
          					if (pixel > 255) pixel = 255;
          					p\[0\] = (byte) pixel;					
          
          					p += 3;
          				}
          				p += nOffset;
          			}
          		}
          
          		b.UnlockBits(bmData);
          
          		return true;
          	}
          
          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups