Question Image comparison

silver89

Member
Joined
Oct 21, 2011
Messages
5
Programming Experience
10+
I have a list of input images of which I'm trying to stack and get all the brightest pixels.

At the moment I'm reading the first file and setting that as the base file, if a pixel in the next read image is brighter then it overwrites the first base image bitmap.

It performs okay for low resolution images but larger images take much much longer as there can be 12,000,000 pixels in a 3000x4000 image.

Would it be better for me to read the files as some sort of array instead of storing them as a bitmap?

Speed is the essence here and I'm not too sure of how I can go about achieving the most efficient method to stack these images?

VB.NET:
For Each Item As String In lbxFiles.Items


                Dim newDrawing As System.Drawing.Bitmap = System.Drawing.Bitmap.FromFile(Item)


                For xCount As Integer = 0 To imageWidth - 1
                    For yCount As Integer = 0 To imageHeight - 1


                        baseColour = baseDrawing.GetPixel(xCount, yCount)
                        newColour = newDrawing.GetPixel(xCount, yCount)


                        If newColour.GetBrightness >= baseColour.GetBrightness Then


                            newDrawing.SetPixel(xCount, yCount, newColour)


                        End If


                    Next yCount
                Next xCount


            Next

Thanks for your help!
 
Research Bitmap.LockBits method for way faster image processing.
 
What do you mean by that? Marshal class is used for interaction with unmanaged code and memory, and since LockBits is about working with unmanaged image data Marshal class is used in all VB.Net code examples you can find for that, including the documentation code samples and the code samples used in the article I linked to.
 
There's a red marker at the end of the squiggly underline, hover it and click 'Error Correction Options', choose to qualify the type by namespace or import the namespace suggested.
If you had to do it manually, for example if the assembly was not loaded and intellisense could not make any suggestions, you would look up the class in documentation to see what assembly and namespace the class belong to, then referenced the assembly and qualify/import the namespace.
 
I looked into all of that and now have it successfully working, although with this new approach I can no longer use:

VB.NET:
 If newColour.GetBrightness >= baseColour.GetBrightness Then

As I think the colours are referenced by HSL? If I'm wanting to compare two different HSL codes to find the brightest of the two would I need to look at converting to rbg or system colors in order to do this comparison?

Thanks once again!
 
Yes, you would. From the rgb values you can calculate brightness, or just load a Color structure with the info and use GetBrightness as before.
 
Back
Top