in Education by
I wanna transform a grayscaled iplimage into uiimage and viceversa. I have two methods like below that are successful in RGB colorspace conversion, But no success for Gray images. - (UIImage *)UIImageFromIplImage:(IplImage *)image { CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); NSData *data = [NSData dataWithBytes:image->imageData length:image->imageSize]; CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)data); CGImageRef imageRef = CGImageCreate(image->width, image->height, image->depth, image->depth * image->nChannels, image->widthStep, colorSpace, kCGImageAlphaNone|kCGBitmapByteOrderDefault, provider, NULL, false, kCGRenderingIntentDefault); UIImage *ret = [UIImage imageWithCGImage:imageRef]; CGImageRelease(imageRef); CGDataProviderRelease(provider); CGColorSpaceRelease(colorSpace); return ret; } - (IplImage *)CreateIplImageFromUIImage:(UIImage *)image { CGImageRef imageRef = image.CGImage; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); IplImage *iplimage = cvCreateImage(cvSize(image.size.width, image.size.height), IPL_DEPTH_8U, 4); CGContextRef contextRef = CGBitmapContextCreate(iplimage->imageData, iplimage->width, iplimage->height, iplimage->depth, iplimage->widthStep, colorSpace, kCGImageAlphaPremultipliedLast|kCGBitmapByteOrderDefault); CGContextDrawImage(contextRef, CGRectMake(0, 0, image.size.width, image.size.height), imageRef); CGContextRelease(contextRef); CGColorSpaceRelease(colorSpace); IplImage *ret = cvCreateImage(cvGetSize(iplimage), IPL_DEPTH_8U, 3); cvCvtColor(iplimage, ret, CV_RGBA2BGR); cvReleaseImage(&iplimage); return ret; } I need help at this point to figure out the problem I have. Thanks in advance.. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
What about convert the color channel before passing in the argument? IplImage *image = cvCreateImage(cvGetSize(imgGray), IPL_DEPTH_32F, 3); cvCvtColor(imgGray, image, CV_GRAY2BGR); imageView.image = [self UIImageFromIplImage:image];

Related questions

0 votes
    Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 7, 2022 in Education by JackTerrance
0 votes
    Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    The ___________ class adds a rounded border around an element with a gray background color and some padding. ... .alert .jumbotron Select the correct answer from above options...
asked Dec 10, 2021 in Education by JackTerrance
0 votes
    Express the decimal number 68.5 in i) bcd code ii) xs-3 code iii) gray code Select the correct answer from above options...
asked Nov 27, 2021 in Education by JackTerrance
0 votes
    What is black when you buy it, red when you use it, and gray when you throw it away? A) Shoe B) Charcoal C) Belt D) All the above...
asked Feb 10, 2021 in Education by JackTerrance
0 votes
    I'm working on migrating/rewriting some Java generics in C#. I'm getting an error that I don't ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 26, 2022 in Education by JackTerrance
0 votes
    I'm working on migrating/rewriting some Java generics in C#. I'm getting an error that I don't ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I'm working on migrating/rewriting some Java generics in C#. I'm getting an error that I don't ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    How do I customize the tab-to-space conversion factor when using Visual Studio Code? For instance, right ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    In scala, it is OK to convert a variable in the Seq, but if I construct the Seq with :: it ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    i create this class and it have this constructor : public class ReturnResult : ImplicitReturnResult { public bool ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    A brief search shows that all available (uUnix command line) tools that convert from xsd (XML Schema) to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 23, 2022 in Education by JackTerrance
0 votes
    I'm looking for a resource in python or bash that will make it easy to take, for example, mp3 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I am developing a software in Android. In a particular portion of software, I need to convert short to byte and re-convert to it ... short n1 = (short)((short)(b1) | (short)(b2...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I am developing a software in Android. In a particular portion of software, I need to convert short to byte and re-convert to it ... short n1 = (short)((short)(b1) | (short)(b2...
asked Feb 18, 2022 in Education by JackTerrance
...