我正在试图找出如何在两个图像上分割带有4个通道(r,g,b,a)的JPEG - 一个应该是带有RGB信息的JPEG,另一个是带有alpha通道的PNG。
答案 0 :(得分:1)
您要下载的是ImageMagick软件包。它有大量的命令行程序,您可以在脚本中使用它们对图像进行“魔术”。
答案 1 :(得分:0)
您可以使用OpenCV用于图像处理的开源库来实现此目的:
// NOTE you SHOULD cvReleaseImage() for the return value when end of the code.
- (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;
}
//detecting blobs and drawing countours arround it
- (void) splitImage : (UIImage *) image {
if(!image)
return;
IplImage *iplImageFromImage = [self CreateIplImageFromUIImage:image];
cvSetImageROI(iplImageFromImage, cvRect(0, 0, image.size.width, image.size.height));
//splitting image detecting blob and then mergin it back
cout <<"channels = "<<iplImageFromImage->nChannels<<"\n";
IplImage *hImage, *sImage, *vImage, *fImage;
cvSplit(iplImageFromImage, &hImage, &sImage, &vImage, &fImage);
CvMat tmp; CvMat* mat = cvGetMat(iplImageFromImage, &tmp, 0, 0);
CvMat *hImage_m = cvCreateMat(mat->rows, mat->cols, CV_8UC1),
*sImage_m = cvCreateMat(mat->rows, mat->cols, CV_8UC1),
*vImage_m = cvCreateMat(mat->rows, mat->cols, CV_8UC1);
cvSplit(mat, hImage_m, sImage_m, vImage_m, NULL);
}
答案 2 :(得分:0)
你想要一些可编写脚本的东西吗? Imagemagick包具有转换实用程序,可以提取图像通道:
convert rose: -channel R -separate separate_red.gif
convert rose: -channel G -separate separate_green.gif
convert rose: -channel B -separate separate_blue.gif
阅读here有关分离频道图像的信息。
Imagemagick在OSX上运行得很好。