Click here to Skip to main content
Click here to Skip to main content

Mango, Photo Editor with OpenCV

By , 10 Dec 2008
 

Introduction

I made a simple but nice photo editor with OpenCV. It can be used to edit photos, such as, adding simple effects, changing the brightness and the contrast, histogram equalization, face detection, etc. For the GUI, I use wxWidgets so it can be easily ported to the Linux operating system.

Background

OpenCV is an open source computer vision library in C/C++. It provides us many APIs for image data manipulation. It is OS independent and optimized for real-time applications. Go to the OpenCV website and download the latest version. Install and check sample directory. Find some tutorials and enjoy.

wxWidgets is an OS independent open source GUI library. By using this library we can make an OS independent application. Check here at the wxWidgets website.

The Plan

Here is the plan. We are going to make a photo editor software that is capable of:

  • Converting an image to grayscale and black and white.
  • Do per channel adjustment of brightness and contrast based on its color space.
  • Change color space: RGB, YCrCb, HSV, and HLS.
  • Rotate, flip, or resize an image.
  • Do histogram equalization.
  • Show histogram graph.
  • Detect faces.
  • Generate erode and dilate effects.
  • Have "UNDO" capability.

The Code

The class for image manipulation is allocated in files mango.h and mango.cpp with name CMango.

class CMango
{

public:
    enum type{
        IM_AUTOMATIC,
        IM_GRAYSCALE,
        IM_BLACKNWHITE,
        IM_RGB,
        IM_HSV,
        IM_HLS,
        IM_YCrCb,
        IM_ZOOMIN,
        IM_ZOOMOUT,
        IM_HORIZONTAL = 25,
        IM_VERTICAL,
        IM_DILATE = 40,
        IM_ERODE,
        IM_FACE1,
    };

    CMango(void);
    ~CMango(void);

    int LoadImageFromFile(char *FileName);
    void ShowActiveImage(char *WindowName);
    int SetProperty();
    std::string GetProperty();
    void LoadPrestoredImage(int type);
    void PushImage(IplImage *Image){ImageList.push_front(Image);};
    void PopImage(){ if (!ImageList.empty()) ImageList.pop_front();};
    int SaveToFile(char *FileName);

    void Rotate(int angle);
    void ZoomImage(int flag);
    int GetImageElement(int channel, int brightness, int contrast);
    void FlipImage(int flag);
    void ApplyEffects(int flag);
    void FaceDetect(int flag);
    void ShowHistogram();
    int HistogramEqualization();
    int ChangeColorSpace(int flag);

private:
    static IplImage *Automatic;
    static IplImage *Blacknwhite;
    static IplImage *Grayscale;
    static IplImage *Buf;

    static std::list<IplImage *> ImageList;
    static std::list<std::string> PropertyList;

    static int ColorSpace;
};

When an image is loaded, it is kept in data member Automatic. Actually we have three pre-stored images here: Automatic, Blacknwhite, and Grayscale. Every operation we perform will push an active image (image that is being displayed) to ImageList so we can perform "undo." The "undo" command basically will popup an image from ImageList to be displayed.

I also did some experiments on color spaces. Adjusting the per-channel brightness and contrast of an image can give us an awesome effect depending on its color spaces. I used an algorithm that I found in this site. Since OpenCV will only put RGB on display, I have to do these: Convert image to target color space, do the adjustment that I want, and finally, convert it back to RGB to be displayed.

Unfortunately, I encountered a problem. The problem is that the algorithm is for RGB color space. I can't just use it for other color spaces. But, take a look at this:

    Range
RGB R 0 - 1
  G 0 - 1
  B 0 - 1
YCrCb Y 0 - 1
  Cr -0.5 - 0.5
  Cb -0.5 - 0.5
HSV H 0-360
  S 0 - 1
  V 0 - 1
HLS H 0-360
  L 0 - 1
  S 0 - 1

Based on this table I think it is possible to apply the same algorithm for other color spaces besides RGB as long as they are in the same range.

Please notice that I only implemented the histogram curve for RGB color space only. If you change the color space, the histogram curve is no longer valid because of difference in range.

Points of Interest

I implemented many basic functions of OpenCV here. I hope It might be useful for you to start learning about OpenCV.

References

License

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

About the Author

auralius manurung
Other Gyeongsang National University, South Korea
Indonesia Indonesia
Member
from Indonesia with love... Smile | :)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generalat compilation: can't find wx/foldbar/foldpanelbar.h [modified]memberLudoTW23 Apr '09 - 16:38 
Hello auralius,
 
Though I can't get the program to compile under linux (Mandriva), I want to thank you for having me discover wxWidget (I can run some simple tutorial programs) and also for clever functions, one of them I have been able to extract from your program and try (the ShowHistogram).
 
Nevertheless, I'd be really glad to be able to compile and run your program.
Compiling it with:
g++ main.cpp main.h Mango.cpp Mango.h `wx-config --cxxflags --libs` -o mango -I/home/ludovic/Programs/cv/opencv/include/opencv -L/home/ludovic/Programs/cv/opencv/lib -lcxcore -lhighgui -lcv
 
Since the first error message I get is:
error: wx/foldpanelbar.h: No such file or directory
 
I did search for a foldpanelbar.h and found it in
wxGTK-2.8.10/contrib/include/wx/foldbar
I copied it into wx/ (where all the other .h file you use seem to be located) and changed the #include in main.h to #include "wx/foldpanelbar.h" but it still can't find it.
 
Any hint, on something which is most likely a benign issue?
 
Thank you
 
Ludo, Taiwan
 
modified on Wednesday, April 29, 2009 2:09 AM

GeneralRe: at compilation: can't find wx/foldbar/foldpanelbar.hmemberauralius1 May '09 - 3:34 
I think you should manually build the libraries for libwxmsw28ud_foldbar.a for usage of wxFoldPanelBar.
Sorry for late reply...
 
From Indonesia with love..!!

GeneralRe: at compilation: can't find wx/foldbar/foldpanelbar.hmemberollydbg2313 May '09 - 15:32 
@auralius
 
This is the problem everybody could encounter when compiling, so, I think you should get your article refined to add some comment about this extra library. Smile | :)

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 10 Dec 2008
Article Copyright 2008 by auralius manurung
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid