iPhone에서 이미지를 양자화 할 수있는 라이브러리가 있습니까?Quantize Image, 남은 색 목록 저장
나는 8 색으로 이미지를 양자화하고 양자화 후에 남은 각 색에 대해 16 진수 또는 rgb 값을 기록하려고합니다.
iPhone에서 이미지를 양자화 할 수있는 라이브러리가 있습니까?Quantize Image, 남은 색 목록 저장
나는 8 색으로 이미지를 양자화하고 양자화 후에 남은 각 색에 대해 16 진수 또는 rgb 값을 기록하려고합니다.
자신을 그렇게하기가 어렵지 않아야합니다. 픽셀 데이터를 가져 와서 반복하고 퀀 타이즈하십시오. 여기서 화소 데이터 얻는 방법 :
(이 코드는 I 믿어 에리카 Sadun 요리 책 샘플로부터 임)
// Courtesy of Apple, Create Bitmap with Alpha/RGB values
CGContextRef CreateARGBBitmapContext (CGImageRef inImage, CGSize size)
{
CGContextRef context = NULL;
CGColorSpaceRef colorSpace;
void * bitmapData;
int bitmapByteCount;
int bitmapBytesPerRow;
size_t pixelsWide = size.width;
size_t pixelsHigh = size.height;
bitmapBytesPerRow = (pixelsWide * 4);
bitmapByteCount = (bitmapBytesPerRow * pixelsHigh);
colorSpace = CGColorSpaceCreateDeviceRGB();
if (colorSpace == NULL)
{
fprintf(stderr, "Error allocating color space\n");
return NULL;
}
// allocate the bitmap & create context
bitmapData = malloc(bitmapByteCount);
if (bitmapData == NULL)
{
fprintf (stderr, "Memory not allocated!");
CGColorSpaceRelease(colorSpace);
return NULL;
}
context = CGBitmapContextCreate (bitmapData, pixelsWide, pixelsHigh, 8,
bitmapBytesPerRow, colorSpace,
kCGImageAlphaPremultipliedFirst);
if (context == NULL)
{
free (bitmapData);
fprintf (stderr, "Context not created!");
}
CGColorSpaceRelease(colorSpace);
return context;
}
// Return a C-based bitmap of the image data inside an image
unsigned char *RequestImagePixelData(UIImage *inImage)
{
CGImageRef img = [inImage CGImage];
CGSize size = [inImage size];
CGContextRef cgctx = CreateARGBBitmapContext(img, size);
if (cgctx == NULL) return NULL;
CGRect rect = {{0,0},{size.width, size.height}};
CGContextDrawImage(cgctx, rect, img);
unsigned char *data = CGBitmapContextGetData (cgctx);
CGContextRelease(cgctx);
return data;
}
을
RequestImagePixelData 각 픽셀의 알파 8 비트, 8 비트로서 설명 된 배열을 반환 빨간색, 8 비트 녹색 및 8 비트 파란색.
이 작업에는 ImageMagick을 사용할 수 있습니다. https://github.com/marforic/imagemagick_lib_iphone MagickQuantizeImage 및 관련 함수가 도움이 될 것입니다.
이 다른 질문 http://stackoverflow.com/questions/9262928/how-to-optimized-this-image-processing-replace-all-pixels-on-image-with-closest이 대답을 참조하고 몇 가지 아이디어가 있습니다. diff 및 팔레트 선택을 수행하는 중입니다. –