— Created 2017-02-12 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" use framework "GPUImage" use framework "Quartz" use framework "QuartzCore" use framework "CoreGraphics"
set aFile to POSIX path of (choose file of type {"public.image"} with prompt "Select a image to check which is blank (or not) ")
set aURL to current application’s |NSURL|’s fileURLWithPath:aFile set anNSImage to current application’s NSImage’s alloc()’s initWithContentsOfURL:aURL
set wRes to my detectAllWhite:anNSImage –> true (Blank = White) –> false (Not Blank = Not White)
–指定のNSImageが真っ白かどうかをチェック on detectAllWhite:anNSImage –グレースケールフィルタを通して色要素を削除 set grayImage to filterWithNSImage(anNSImage, "GPUImageGrayscaleFilter") of me –明度ヒストグラム画像を取得 set imgRes to getHistogramFromImage(grayImage, 4) of me –画像のサイズ(幅、高さ)をピクセル数で取得する(念のため) set aSize to imgRes’s |size|() set aWidth to aSize’s width() set aHeight to aSize’s height() set aRawimg to current application’s NSBitmapImageRep’s imageRepWithData:(imgRes’s TIFFRepresentation()) –白い画像のデータパターン set aWhitePattern to current application’s NSMutableArray’s arrayWithArray:{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0} set resArray to current application’s NSMutableArray’s alloc()’s init() repeat with i from 0 to 255 set origColor to (aRawimg’s colorAtX:i y:1) set srgbColSpace to current application’s NSColorSpace’s genericGrayColorSpace set aColor to (origColor’s colorUsingColorSpace:srgbColSpace) set aWhite to aColor’s whiteComponent() (resArray’s addObject:aWhite) end repeat set aRes to (resArray’s isEqualTo:aWhitePattern) as boolean return aRes end detectAllWhite:
–各種ヒストグラムの定数(From GPUImage.framework) –0:kGPUImageHistogramRed –1:kGPUImageHistogramGreen –2:kGPUImageHistogramBlue –3:kGPUImageHistogramRGB –4:kGPUImageHistogramLuminance
–指定のNSImageを明度ヒストグラム化してNSImageで返す on getHistogramFromImage(aNSImage, histogramType) set aFilter to current application’s GPUImageHistogramFilter’s alloc()’s initWithHistogramType:histogramType set aProcImg to (aFilter’s imageByFilteringImage:aNSImage) return aProcImg end getHistogramFromImage
–NSImageをGPUImage.frameworkの指定フィルタで処理してNSImageを返す on filterWithNSImage(aNSImage, filterName as string) set aClass to current application’s NSClassFromString(filterName) set aImageFilter to aClass’s alloc()’s init() set aProcImg to (aImageFilter’s imageByFilteringImage:aNSImage) return aProcImg end filterWithNSImage
|