指定画像の余白トリミングを自動で行うAppleScriptです。
KGPixelBoundsClipKit.framework (To ~/Library/Frameworks/)
AppleScript名:指定画像の余白の自動トリミング |
— Created 2017-04-26 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" use framework "KGPixelBoundsClipKit" –https://github.com/kgn/KGPixelBoundsClip set aFile to POSIX path of (choose file of type {"public.image"}) set anImage to (current application’s NSImage’s alloc()’s initWithContentsOfFile:aFile) set bImage to anImage’s imageClippedToPixelBounds() set aDesktopPath to (current application’s NSProcessInfo’s processInfo()’s environment()’s objectForKey:("HOME"))’s stringByAppendingString:"/Desktop/" set savePath to aDesktopPath’s stringByAppendingString:((current application’s NSUUID’s UUID()’s UUIDString())’s stringByAppendingString:".png") set fRes to saveNSImageAtPathAsPNG(bImage, savePath) of me –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 end saveNSImageAtPathAsPNG |
More from my site
(Visited 385 times, 1 visits today)
CreateMLで機械学習したモデルを利用して、MSの画像の連邦、ジオン軍判定 – AppleScriptの穴 says:
[…] 度が下がっているように見えます。結局画像は299×299ピクセルぐらいに縮小されて判定されるので、判定前に画像余白部分をトリミングしておくと認識精度が上がりそうな気もします。 […]
KGPixelBoundsClipがmacOS 15で動作しない? – AppleScriptの穴 says:
[…] → 指定画像の余白の自動トリミング […]