LabWindows/CVI User Group Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

Color-to-grayscale or -to-monochrome conversion

Introduction

This sample was originated from this thread in the Discussion Forums. As mentioned there, I developed a simple application to perform conversion from file to file.

Next I extended the original project to treat both images from file and images already in memory, like as an example those taken with GetPanelBitmap or GetCtrlBitmap. Memory bitmaps, infact, always honour the screen colour depth regardless the parameter passed to NewBitmap command, and since nowadays 24- or 32-bit colour depth are common it seems that it is not possible to create a monochrome or grayscale bitmap in memory with native CVI commands only.

While converting to grayscale produces almost always meaningful images, conversion to monochrome is very dependent on the discrimination level that you apply to determine whether a given pixel must be converted to black or white. The effect of this discrimination level is very dependent on the characteristics of the image to be converted, so I decided to give the user the possibility to modify it.

In the attached document I add some sample images to test, but the application permits to select any image on disk. As an example, the following is a JPG colour image and the corresponding grayscale converted BMP produced by the application:

testimg.jpgtestimg_8bit.bmp

Documentation

Documentation on BMP file format can be found in this Wikipedia page, while conversion to grayscale is described in this other page.

Additional Notes

While dealing with .BMP files can be of little interest with the possibilty offered by CVI to treat other graphic file formats with a good level of compression, this sample can still be useful as it shows how to read / write binary files using structures to directly decode formatted informations.

It also shows some of the error trapping techniques I described in this contribution.

Application software

The application has been developed with CVI 8.5.1 Full development system. Nevertheless, it should use no functions specific to that version so that it should be possible to run it in base development system too. I cannot test this option, though, as we are using the full version.

Downgrading

I downgraded the project for users with an older IDE: the attached converter71 file includes the complete project running in CVI 7.1



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Download All
Comments
Member
Member
on

Very useful application.

One thing that would help this article would be pictures.  A simple example of a before and after image would be helpful to a user like myself who has very little time to try the software out.

S G
Certified LabVIEW Architect, Certified TestStand Architect, Certified Professional Instructor
佩林
Member
Member
on

Very good application.

I wouldn't care success or failure,for I will only struggle ahead as long as I have been destined to the distance.
佩林
Member
Member
on

Hi !

My CVI version is 8.0.This useful application format is newer than my CVI version.

I want ro study how to convert high colour depth images into grayscale or monochrome images, smaller in size.

Could you help me convert this high version into a low version ?

Thank you very much !

I wouldn't care success or failure,for I will only struggle ahead as long as I have been destined to the distance.
RobertoBozzolo
Proven Zealot
Proven Zealot
on

I added a downgraded release of the project running in CVI 7.1



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
佩林
Member
Member
on

Thank you very much indeed !

Best wishes for you !

I wouldn't care success or failure,for I will only struggle ahead as long as I have been destined to the distance.
Contributors