▲Original Image
▲Filtered Image
AppleScript名:指定画像の明度ヒストグラム画像を出力する |
— 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" –https://github.com/BradLarson/GPUImage set aFile to POSIX path of (choose file of type {"public.image"} with prompt "Select a Image to check it is white (or not) ") set anNSImage to current application’s NSImage’s alloc()’s initWithContentsOfFile:aFile set wRes to getHistogramFromImage(anNSImage, 4) of me set aPath to (POSIX path of (path to desktop) & (current application’s NSUUID’s UUID())’s UUIDString() as string) & ".png" set fRes to saveNSImageAtPathAsPNG(wRes, aPath) of me –指定のNSImageをGPUImage.frameworkで明度ヒストグラム化して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 –NSImageを指定パスにPNG形式で保存 on saveNSImageAtPathAsPNG(anImage, outPath) set imageRep to anImage’s TIFFRepresentation() set aRawimg to current application’s NSBitmapImageRep’s imageRepWithData:imageRep set pathString to current application’s NSString’s stringWithString:outPath set newPath to pathString’s stringByExpandingTildeInPath() set myNewImageData to (aRawimg’s representationUsingType:(current application’s NSPNGFileType) |properties|:(missing value)) set aRes to (myNewImageData’s writeToFile:newPath atomically:true) as boolean return aRes –true/false end saveNSImageAtPathAsPNG |
More from my site
(Visited 51 times, 1 visits today)