2

Lanczos Scale Transform フィルターを使用して、Core Image を使用して画像のスケーリングを実行しようとしています。スケールアップしているときは問題ありません。しかし、縮小してJPEGに保存すると、奇妙なノイズアーティファクトと動作を生成する画像のクラスが見つかりました。

inputScale の倍数が 0.5 の場合: 0.5、0.25、0.125 などは常に問題ありません。他のinputScale値については壊れています。

TIFF、PNG、JPEG2000 に保存するとき、または画面に描画するときは問題ありません。JPG または BMP に保存すると、壊れてしまいます。

サンプル画像をアップロードしました: ( original, 4272x2848 , 3.4Mb )

(ノイズでスケーリング、1920x1280、2.2Mb ) [ http://www.zoomfoot.com/get/package/6eb64d33-3a30-4e8d-9953-67ce1e7d7ef9]

また、「夕焼け」の画像でもかなりよく再現されています。

画像をスケーリングする方法をさらにいくつか試しました。CIAffineTransform を使用し、NSImage 自体を使用して描画します。どちらもノイズのない結果を提供します。

スケーリングと保存に使用していたコードは次のとおりです。

================= ランチョス ==============


- (NSImage *) scaleLanczosImage:(NSString *)path Width:(int) desiredWidth Height:(int) desiredHeight { CIImage *image=[CIImage imageWithContentsOfURL: [NSURL fileURLWithPath:path]];

CIFilter *scaleFilter = [CIFilter filterWithName:@"CILanczosScaleTransform"]; int originalHeight=[image extent].size.height; int originalWidth=[image extent].size.width;

float yScale=(float)desiredHeight / (float)originalHeight; float xScale=(float)desiredWidth / (float)originalWidth; float scale=fminf(yScale, xScale);

[scaleFilter setValue:[NSNumber numberWithFloat:scale] forKey:@"inputScale"]; [scaleFilter setValue:[NSNumber numberWithFloat:1.0] forKey:@"inputAspectRatio"]; [scaleFilter setValue: image forKey:@"inputImage"];

image = [scaleFilter valueForKey:@"outputImage"];

NSBitmapImageRep* rep = [[NSBitmapImageRep alloc] initWithCIImage:image]; NSMutableDictionary *options=[NSMutableDictionary dictionaryWithObject:[NSDecimalNumber numberWithFloat:1.0] forKey:NSImageCompressionFactor];

[options setValue:[NSNumber numberWithBool:YES] forKey:NSImageProgressive]; NSData* jpegData = [rep representationUsingType:NSJPEGFileType properties:options];

[jpegData writeToFile:@"/Users/dmitry/tmp/img_4389-800x600.jpg" atomically:YES]; }

================= NSImage ==============


- (void) scaleNSImage:(NSString *)path Width:(int) desiredWidth Height:(int) desiredHeight { NSImage *sourceImage = [[NSImage alloc] initWithContentsOfFile:path]; NSImage *resizedImage = [[NSImage alloc] initWithSize: NSMakeSize(desiredWidth, desiredHeight)];

NSSize originalSize = [sourceImage size];

[resizedImage lockFocus]; [sourceImage drawInRect: NSMakeRect(0, 0, desiredWidth, desiredHeight) fromRect: NSMakeRect(0, 0, originalSize.width, originalSize.height) operation: NSCompositeSourceOver fraction: 1.0];

[resizedImage unlockFocus];

NSMutableDictionary *options=[NSMutableDictionary dictionaryWithObject:[NSDecimalNumber numberWithFloat:1.0] forKey:NSImageCompressionFactor];

[options setValue:[NSNumber numberWithBool:YES] forKey:NSImageProgressive];

NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithData:[resizedImage TIFFRepresentation]];

NSData* jpegData = [rep representationUsingType:NSJPEGFileType properties:options];

[jpegData writeToFile:@"~/nsimg_4389-800x600.jpg" atomically:YES];

}

誰かがここで何かを説明または提案できる場合は、本当に感謝しています。

ありがとう。

4

3 に答える 3

1

私の理解では、その性質上、ハードウェアのコア イメージ レンダラーには、画面上の表示以外のレンダリングを行うときに、いくつかの奇妙な癖があります。そのため、他の状況ではソフトウェア レンダラーを使用することをお勧めします。

http://developer.apple.com/mac/library/qa/qa2005/qa1416.html

于 2010-02-05T16:38:09.343 に答える
1

CIImage によるスケーリングにはいくつかの癖があります。ダン・ウッドによるこの投稿は役に立ちますか?

于 2010-02-05T11:34:39.967 に答える
0

これは間違いなく CoreImage のバグです。bugreport.apple.com にファイルしてください。

于 2010-02-05T13:38:12.290 に答える