I have two problems converting my image (only jpeg-files) from NSImage to IplImage. My first problem is that the converted image has not the same colour intensity like the original one. The converted image is somehow more toneless than the original one.
My second problem is only 8/10 images are converted totally, by 2/10 images only a part of the image will be converted. What I mean is that only the upper left corner of the image will be converted. I hope you understand me, my english is not the best.
IplImage* convert(NSImage* bild){
//converting the NSImage into an IplImage
NSBitmapImageRep *bitmap2 = [NSBitmapImageRep imageRepWithData:[bild TIFFRepresentation]];
int depth = [bitmap2 bitsPerSample];
int channels = [bitmap2 samplesPerPixel];
int height = [bitmap2 size].height;
int width = [bitmap2 size].width;
IplImage *iplpic = cvCreateImage(cvSize( width,height), depth, channels);
cvSetImageData(iplpic, [bitmap2 bitmapData], [bitmap2 bytesPerRow]);
for (int i = 0; i < iplpic->imageSize; i += 3) {
uchar tempR, tempG, tempB;
tempR = iplpic->imageData[i];
tempG = iplpic->imageData[i+1];
tempB = iplpic->imageData[i+2];
iplpic->imageData[i+2] = tempR;
iplpic->imageData[i+1] =tempG;
iplpic->imageData[i] = tempB;
}
cvSaveImage("/Users/goette/out.jpg", iplpic, 0);
return iplpic;
}