Digital Image Processing

Posted on 2001-07-18
Last Modified: 2012-06-27
How to write programs in Visual Basic to do the following intensity transformations:
1) Image negatives
2)Contrast stretching
3)Gray level slicing
4)Bit plane slicing
5)Histogram equalization
6)Low pass spatial filtering using 3*3 mask
Question by:Emmiediana
LVL 22

Expert Comment

ID: 6293454
You will need to use the API. You will need to write code that can examine each and every single pixel, and the pixels around it. I have done quite some digital image processing in C++, and can show you a simple sample in C++. (The functions are mainly the same as in VB, you will just need to add the appropriate API functions).

If you want I can send you an email with the sample...the code is in C++ though which is better for digital image processing in my opinion. I have the sample at home...

LVL 17

Accepted Solution

inthedark earned 75 total points
ID: 6293746
Images in VB a quite simple.  The hard bit is knowing what to do to each pixel to get the desired effect.

All image functions are a variation of the following VB code:

Add a pixture box & a command button to a form.

Edit the properties of the picture box and load an image into the picture property.

Paste the following code.
And run.

Sub Command1_Click

Dim x As Long
Dim y As Long
Dim h As Long
Dim w As Long
Dim col As Long

Dim red As Long
Dim green As Long
Dim blue As Long
Dim P As PictureBox

' Make sure the picture and form have a scalemode of pixels.

Me.ScaleMode = 3
Set P = Picture1
P.BorderStyle = 0
P.ScaleMode = 3 ' pixel

' w & h = no. of pixels to process
h = P.Height
w = P.Width

' loop through each pixel
For y = 0 To h
    For x = 0 To w

        col = P.Point(x, y) ' get the current pixel colour

        ' break down into parts
        ' you could speed this up using "And"
        red = Int(col / 65536)
        green = Int(col / 256) - red * 256
        blue = col as 255
        ' make a colour negative
        red = 255 - red
        green = 255 - green
        blue = 255 - blue
        col = RGB(red, green, blue)

        P.PSet (x, y), col ' paint the new colour back ontop of the old pixel

    Next x
Next y

LVL 17

Expert Comment

ID: 6293774
All you need now are the algorithms for:

2)Contrast stretching
3)Gray level slicing
4)Bit plane slicing
5)Histogram equalization
6)Low pass spatial filtering using 3*3 mask

The net is probably the best source for a solution to this:


Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

LVL 17

Expert Comment

ID: 6293778
But CJ_S is right that C would be better for this job.

Expert Comment

ID: 6294498
Check out this book:

Visual Basic Graphics Programming (2nd Ed), Hands-On Applications and Advanced Color Development, Rod Stevens

It has tons of algorithms (easy to advanced), including most of the one's you are looking for.


Author Comment

ID: 6304203
To all that have posted their comments regarding my question on digital image processing..thanx a lot!!
Anyway..i still need your help....:)

To CJ,
Could you please send me those codes in C++?? :)
I'm really looking forward to view the codes and study them...

To inthedark,
Thanx for the VB codes...
I've tried it out ...and now i got some ideas to do the other intensity transformations...
(Anyway,frankly speaking...i still find it difficult..
anyone can help me??? :) )
btw...thanx for the url address....

To slider 115,
thanx for suggesting me the book..:)

LVL 22

Expert Comment

ID: 6329596
I tried sending them to you yesterday at work. But I got it returned... so I have send another email saying that your mailbox was probably full. I don't know whether you have replied yet, but i will see that on monday.... or else, give me your email addy again (which can take 1.2 MB)

LVL 17

Expert Comment

ID: 6330759
In the previous example to make the image monochrome:

red = (reg+green+blue)/3

col = RGB(red, green, blue)

Sounds like a fun project.

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question