cloudelin / javacv

Automatically exported from code.google.com/p/javacv
0 stars 0 forks source link

Histogram Equalization - wrong format after cvCreateImage? #25

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Histogram Equalization:
public BufferedImage Equalize(BufferedImage img)
{
    IplImage img = IplImage.createFrom(img);
    IplImage out = cvCreateImage(cvSize(img.width, img.height), IPL_DEPTH_8U, 1);       

    // Perform histogram equalization
    cvEqualizeHist( out, out );

        BufferedImage eqimg = out.getBufferedImage();
    out.release();

        return eqimg;    
}

What is the expected output? What do you see instead?
The returned equalized image "eqimg" is not displayable on my GUI. The "img" I 
pass into the function however works fine, but not the returned "eqimg".

What version of the product are you using? On what operating system?
Lastest javacv version, Windows 7.

Please provide any additional information below.
Even if I perform a simple grayscale conversion, it has the same problem:
public BufferedImage GrayConversion(BufferedImage img)
{
    IplImage img = IplImage.createFrom(img);
    IplImage out = cvCreateImage(cvSize(img.width, img.height), IPL_DEPTH_8U, 1);       

    BufferedImage grayimg = out.getBufferedImage();
    out.release();

        return grayimg;   
}

Hence, I might be doing something wrong in the following line?:
IplImage out = cvCreateImage(cvSize(img.width, img.height), IPL_DEPTH_8U, 1);

Original issue reported on code.google.com by pendieee...@hotmail.com on 4 Oct 2010 at 11:19

GoogleCodeExporter commented 9 years ago
Did you try cvEqualizeHist( img, out ) instead?

Original comment by samuel.a...@gmail.com on 4 Oct 2010 at 11:32

GoogleCodeExporter commented 9 years ago
Yes, but even wors; it compiles, but it crashes on Runtime..
How about the Grayscale conversion problem?

Original comment by pendieee...@hotmail.com on 4 Oct 2010 at 12:04

GoogleCodeExporter commented 9 years ago
I made some changes to that recently to fix issue #24. Can you try with this 
test package instead and see what happens? thanks
    http://www.ok.ctrl.titech.ac.jp/~saudet/javacv.jar

Original comment by samuel.a...@gmail.com on 4 Oct 2010 at 1:12

GoogleCodeExporter commented 9 years ago
Unfortunately it's still the same..

Original comment by pendieee...@hotmail.com on 4 Oct 2010 at 2:36

GoogleCodeExporter commented 9 years ago
If you are trying to convert a color image to a gray image, you should used the 
cvCvtColor() function, as exemplified in the README.txt file:
            // Let's try to detect some faces! but we need a grayscale image...
            cvCvtColor(grabbedImage, grayImage, CV_BGR2GRAY);
Does the cvCvtColor() function work or not?

Original comment by samuel.a...@gmail.com on 5 Oct 2010 at 11:43

GoogleCodeExporter commented 9 years ago
That works perfect for grayscale!

However, we still have the problem with histogram equalization. In particular, 
I have found that the problem might be with the cvCreateImage part: I created a 
function to test just cvCreateImage, and in fact it does not work:
public BufferedImage testcvCreateImage(BufferedImage animg)
{
    IplImage img = IplImage.createFrom(animg);

        IplImage testimg = cvCreateImage(cvSize(img.width, img.height), IPL_DEPTH_8U, 1);       

        BufferedImage testBufferedimg = testimg.getBufferedImage();

        return testBufferedimg; //NOT DISPLAYABLE       
}

This might be causing the histogram equalization to fail? Or it may need to be 
treated as a new, separate issue?

Original comment by pendieee...@hotmail.com on 5 Oct 2010 at 12:35

GoogleCodeExporter commented 9 years ago
What do you mean "NOT DISPLAYABLE"? What happens? testimg is an initialized 
image, it's not going to contain anything interesting..

Original comment by samuel.a...@gmail.com on 5 Oct 2010 at 1:33

GoogleCodeExporter commented 9 years ago
True, I was doing it the wrong way. For future readers looking for a sample 
code in javacv for histogram equalization, this sample function code works just 
fine (thanks Samuel, you can now close this issue):
public BufferedImage Equalize(BufferedImage bufferedimg)
    {
        IplImage iploriginal = IplImage.createFrom(bufferedimg);

        IplImage srcimg = IplImage.create(iploriginal.width, iploriginal.height, IPL_DEPTH_8U, 1);
        IplImage destimg = IplImage.create(iploriginal.width, iploriginal.height, IPL_DEPTH_8U, 1);

        cvCvtColor(iploriginal, srcimg, CV_BGR2GRAY);

    cvEqualizeHist( srcimg, destimg );

        BufferedImage eqimg = destimg.getBufferedImage();

        return eqimg;
    }

Original comment by pendieee...@hotmail.com on 5 Oct 2010 at 2:29

GoogleCodeExporter commented 9 years ago
Good!

Original comment by samuel.a...@gmail.com on 8 Oct 2010 at 3:01