-
Notifications
You must be signed in to change notification settings - Fork 22
Description
The page https://artraweditor.github.io/AItools contains some shell scripts that run AI tools. These scripts are not applicable on Windows, yet the functionality they provide is highly desirable on any platform.
I would like to contribute the instruction for using AI masks on Windows.
The SMART tool that the guide mentions has pre-built portable releases for Windows (x64). Download release v0.2, which, at the time of this writing, is the latest version:
https://github.com/artraweditor/SMART/releases/download/0.2/SMART-0.2-win64-portable.7z
Extract it under %LOCALAPPDATA%. That is, press Win+R, type "%LOCALAPPDATA%" in the address bar (with the surrounding quotes), press Enter, and then extract the archive into the folder that opens.
Navigate to the resulting SMART-0.2-win64-portable folder. Download one of the SAM 2 model checkpoints from https://github.com/facebookresearch/sam2?tab=readme-ov-file#download-checkpoints and put it in the models subdirectory.
Then run the SMART.exe program. It will create a configuration file, artpixls-SMART.json, in %LOCALAPPDATA%. Edit it using Notepad and adjust the "model" value to match the model you downloaded. For example:
"model": "sam2.1_hiera_base_plus.pt",
Check that the "device" value is set to "cpu".
Then go to the "%LOCALAPPDATA%\ART" folder. Create the usercommands subfolder if it doesn't exist. Then, place two files there:
smart_masking.ps1:
# --- USER SETTINGS ----------------------------------------------------------
# Automatic ART-cli discovery
$ArtRoot = "C:\Program Files\ART"
# Automatic SMART portable discovery under %LOCALAPPDATA%
$SmartRoot = $env:LOCALAPPDATA
# -----------------------------------------------------------------------------
# Function: show an error dialog
function Show-ErrorBox($Message, $Title = "SMART Error") {
Add-Type -AssemblyName PresentationFramework
[System.Windows.MessageBox]::Show($Message, $Title, 'OK', 'Error') | Out-Null
}
# ------------------- Locate ART-cli (newest version) ------------------------
$ArtDir = Get-ChildItem -Path $ArtRoot -Directory |
Where-Object { $_.Name -match '^\d+\.\d+\.\d+$' } |
Sort-Object { [version]$_.Name } -Descending |
Select-Object -First 1
if (-not $ArtDir) {
Show-ErrorBox "Could not find any ART installation in:`n$ArtRoot"
exit 1
}
$ArtCli = Join-Path $ArtDir.FullName "art-cli.exe"
if (-not (Test-Path $ArtCli)) {
Show-ErrorBox "ART-cli was not found at:`n$ArtCli"
exit 1
}
# ------------------- Locate SMART portable (newest version) -----------------
$SmartDir = Get-ChildItem -Path $SmartRoot -Directory |
Where-Object { $_.Name -match '^SMART-\d+(\.\d+)*-win64-portable$' } |
Sort-Object {
# Extract version number from folder name
[version]($_.Name -replace '^SMART-','' -replace '-win64-portable$','')
} -Descending |
Select-Object -First 1
if (-not $SmartDir) {
Show-ErrorBox "Could not find any SMART portable installation in:`n$SmartRoot"
exit 1
}
$SmartExe = Join-Path $SmartDir.FullName "SMART.exe"
if (-not (Test-Path $SmartExe)) {
Show-ErrorBox "SMART.exe was not found in:`n$($SmartDir.FullName)"
exit 1
}
# ------------------- Validate input RAW file --------------------------------
if ($args.Count -eq 0) {
Show-ErrorBox "No input file received from ART."
exit 1
}
$InputFile = $args[0]
if (-not (Test-Path $InputFile)) {
Show-ErrorBox "Input file does not exist:`n$InputFile"
exit 1
}
# ------------------- Create a temporary directory ---------------------------
$TempDir = New-Item -ItemType Directory -Path ([System.IO.Path]::GetTempPath()) -Name ("ART_SMART_" + [System.Guid]::NewGuid().ToString()) -Force
$Profile = Join-Path $TempDir "p1.arp"
$OutputFile = Join-Path $TempDir "out.jpg"
$ErrorLog = Join-Path $TempDir "error.txt"
# ------------------- Write minimal ARP profile ------------------------------
@"
[Version]
Version=1037
[Crop]
Enabled=false
"@ | Out-File -Encoding ascii $Profile
# ------------------- Run ART-cli -------------------------------------------
# Remove the "-f" if you want the SMART tool to work on the source-resolution image instead of a downscaled version.
# This is slow but keeps mask edge artifacts to the minimum possible.
$ArtArgs = @(
"-f"
"-d"
"-s"
"-p", $Profile
"-Y"
"-j"
"-o", $OutputFile
"-c", $InputFile
)
& $ArtCli @ArtArgs 2> $ErrorLog
# ------------------- Check for errors ---------------------------------------
if (-not (Test-Path $OutputFile)) {
$ErrMsg = ""
if (Test-Path $ErrorLog) {
$ErrMsg = Get-Content $ErrorLog -Raw
}
if ([string]::IsNullOrWhiteSpace($ErrMsg)) {
$ErrMsg = "ART-cli did not produce output, but no error message was available."
}
Show-ErrorBox $ErrMsg
Remove-Item -Recurse -Force $TempDir
exit 1
}
# ------------------- Rename to <raw>_SMART*.jpg -----------------------------
$Base = [System.IO.Path]::GetFileNameWithoutExtension($InputFile)
$Dir = Split-Path $InputFile -Parent
$Target = Join-Path $Dir "${Base}_SMART.jpg"
$i = 1
while (Test-Path $Target) {
$Target = Join-Path $Dir ("${Base}_SMART-$i.jpg")
$i++
}
Move-Item -Force $OutputFile $Target
# ------------------- Call SMART.exe -----------------------------------------
Start-Process -FilePath $SmartExe -ArgumentList "`"$Target`""
# ------------------- Cleanup -------------------------------------------------
Remove-Item -Recurse -Force $TempDir
exit 0
(DISCLOSURE: The script above was generated using ChatGPT v5.1 as an idiomatic translation of the idea in the existing Linux shell script, with added version auto-discovery, and then edited manually until it worked. I certify that I reviewed the script manually before pasting it into this issue.)
smart_masking.txt:
[ART UserCommand]
Label=AI masking (SMART)
Command=powershell.exe -NoProfile -NoExit -ExecutionPolicy Bypass -File .\\smart_masking.ps1