Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6920659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:10:33+00:00 2026-05-27T10:10:33+00:00

When trying to do the watershed method i got this error: Unsupported format or

  • 0

When trying to do the watershed method i got this error:Unsupported format or combination of formats (Only 32-bit, 1-channel output images are supported) in cvWatershed

I think this is because my markers has 3 channels and a depth of 8. I think i need to convert this 3channel 8 depth image to a 32 bit 1 channel image. My question is am i right? and how do i do this conversion?

EDIT: Updated code with solutions

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kitouch;

import org.OpenNI.*;
import com.googlecode.javacpp.Loader;
import com.googlecode.javacv.*;
import com.googlecode.javacv.cpp.*;
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_calib3d.*;
import static com.googlecode.javacv.cpp.opencv_objdetect.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;
import java.nio.ShortBuffer;
import java.awt.*;
import java.awt.image.*;

/**
 *
 * @author olivierjanssens
 */
public class watherShedExample {


   // CanvasFrame frame5 = new CanvasFrame("Some T");
    public static void main(String s[])
    {
    CanvasFrame frame1 = new CanvasFrame("Foreground");
    CanvasFrame frame2 = new CanvasFrame("Dilated");
    CanvasFrame frame3 = new CanvasFrame("Background");
    CanvasFrame frame4 = new CanvasFrame("Markers");
    CanvasFrame frame5 = new CanvasFrame("Watershed");
        // Read input image
    IplImage image = cvLoadImage("/Users/olivierjanssens/Downloads/images/group.jpg");
    IplImage test = cvLoadImage("/Users/olivierjanssens/Downloads/images/binary.bmp");

    IplImage binary = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
     cvCvtColor(test, binary, CV_BGR2GRAY);

    // Eliminate noise and smaller objects, repeat erosion 6 times
    IplImage fg = cvCreateImage(cvGetSize(binary), binary.depth(), binary.nChannels() /* channels */);
    cvErode(binary, fg, null /* 3x3 square */ , 6 /* iterations */);
    frame1.showImage(fg);


    // Identify image pixels pixels objects
    IplImage bg = cvCreateImage(cvGetSize(binary), binary.depth(), binary.nChannels() /* channels */);
    cvDilate(binary, bg, null /* 3x3 square */ , 6 /* iterations */);
    frame2.showImage(bg);

    cvThreshold(bg, bg, 1 /* threshold */ , 128 /* max value */ , CV_THRESH_BINARY_INV);
    frame3.showImage(bg);

    // Create marker image
    IplImage markers = cvCreateImage(cvGetSize(binary), IPL_DEPTH_8U, binary.nChannels() /* channels */);
    cvAdd(fg, bg, markers, null);
    frame4.showImage(markers);
/*
     * TEST SOLUTION 1
    IplImage gray = cvCreateImage(cvGetSize(markers), IPL_DEPTH_8U, 1); 
    cvCvtColor(markers, gray, CV_BGR2GRAY);

    IplImage img32bit1chan = cvCreateImage(cvGetSize(gray), IPL_DEPTH_32F, 1);

    double ve;
    for (int i = 0; i < gray.width(); i++) // markers width
    {
       for (int j = 0; j < gray.height(); j++) // markers height
       {
           ve = cvGetReal2D((IplImage)gray, j, i); 
           cvSetReal2D((IplImage)img32bit1chan , i, j, ve);
       }
    }
*/

    //SOLUTION 2 
    IplImage markers32f = cvCreateImage(cvGetSize(binary), IPL_DEPTH_32F, binary.nChannels());
    cvConvertScale(markers, markers32f, 1, 0); // converts from IPL_DEPTH_8U to IPL_DEPTH_32F


    cvWatershed(image, markers32f);

    frame5.showImage(image);

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:10:34+00:00Added an answer on May 27, 2026 at 10:10 am

    A manual conversion would look something like the following (haven’t tested the code):

    IplImage gray = cvCreateImage(cvGetSize(markers), IPL_DEPTH_8U, 1); 
    cvCvtColor(markers, gray, CV_BGR2GRAY);
    
    IplImage img32bit1chan = cvCreateImage(cvGetSize(gray), IPL_DEPTH_32S, 1);
    
    // convert 8-bit 1-channel image to 32-bit 1-channel
    cvConvertScale(gray, img32bit1chan , 1/255.);
    
    cvWatershed(image, img32bit1chan);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get my css / C# functions to look like this: body {
Trying to keep all the presentation stuff in the xhtml on this project and
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
I'm getting a 'module object has no attribute ... error when trying to use
I've spent the last 2 days trying to figure this out, basically I have
I am trying to convert the Matlab function watershed into C# or C++. I
Trying to follow this tutorial Walkthrough: Part 1 - Creating a Basic Project System
Trying to use the http://www.dinnermint.org/css/creating-triangles-in-css/ method to create an arrow _________________ \ \ \
Trying to launch and pass tel. no. to skype by this code from my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.