1---------------------------------------------------------------- 2---------------------------------------------------------------- 3-- Enfuse droplet applescript 0.0.2 4-- Harry van der wolf 15 Mar 2008 5---------------------------------------------------------------- 6---------------------------------------------------------------- 7on FUNC_ABOUT() 8 display dialog "Enfuse droplet 0.0.2 by Harry van der Wolf" & return & return & � 9 "This (G)UI wrapper uses enfuse and align_image_stack " & � 10 "to fuse your set of images with different exposure " & � 11 "settings to one fused image." & return & return & � 12 "You can use this GUI either by starting it " & � 13 "manually and then select your images" & � 14 return & return & "OR" & return & return & � 15 "drag and drop your images onto this little application." buttons {"Ok"} 16 17end FUNC_ABOUT 18---------------------------------------------------------------- 19---------------------------------------------------------------- 20on FUNC_AIS_PARAM() 21 display dialog "align_image_stack parameters" & return & return & � 22 "# default parameters already set by this script:" & return & � 23 "-p file, output .pto => set to pano.pto" & return & � 24 "-a prefix align images => set to fused" & return & return & � 25 "# other parameters (to be set by you):" & return & � 26 "-e assume input images are full frame fish eye (default: rectilinear)" & return & � 27 "-t num Remove all control points with an error higher than num pixels (default: 3)" & return & � 28 "-f HFOV approximate horizontal field of view of input images, use if EXIF info not complete" & return & � 29 "-m Optimize field of view for all images, except for first. Useful for aligning focus stacks with slightly different magnification." & return & � 30 "-c num number of control points (per grid) to create between adjacent images (default: 8)" & return & � 31 "-l Assume linear input files" & return & � 32 "-s scale Scale down image by 2^scale (default: 1 [2x downsampling])" & return & � 33 "-g gsize Break image into a rectangular grid (gsize x gsize) and attempt to find 34 num control points in each section (default: 5 [5x5 grid] )" & return & return � 35 buttons {"Ok"} 36 37end FUNC_AIS_PARAM 38---------------------------------------------------------------- 39---------------------------------------------------------------- 40on FUNC_ENF_PARAM() 41 display dialog "==== enfuse, version 3.1 ====" & return & � 42 "Common options:" & return & � 43 " -l number Number of levels to use (1 to 29)" & return & � 44 " -o filename Write output to file" & return & � 45 "-w Blend across -180/+180 boundary" & return & � 46 "--compression=COMP Set compression of the output image." & return & � 47 "Valid values for compression are:" & return & � 48 "For TIFF files: LZW, DEFLATE" & return & � 49 "For JPEG files: 0-100" & return & return & � 50 "Extended options:" & return & � 51 "-b kilobytes Image cache block size (default=2MiB)" & return & � 52 "-c Use CIECAM02 to blend colors" & return & � 53 "-g Associated alpha hack for Gimp (ver. < 2) and Cinepaint" & return & � 54 "-f WIDTHxHEIGHT+x0+y0 Manually set the size and position of the output image." & return & � 55 "Useful for cropped and shifted input TIFF images," & � 56 "such as those produced by Nona." & � 57 "-m megabytes Use this much memory before going to disk (default=1GiB)" & return & return & � 58 "Fusion options:" & return & � 59 "--wExposure=W Weight given to well-exposed pixels (from 0 to 1)." & return & � 60 "default value: 1.0" & return & � 61 "--wSaturation=W Weight given to highly-saturated pixels (from 0 to 1)." & return & � 62 "default value: 0.2" & return & � 63 "--wContrast=W Weight given to high-contrast pixels (from 0 to 1)." & return & � 64 "default value: 0" & return & � 65 "--HardMask Force hard blend masks (no averaging) on finest" & � 66 "scale. This is especially useful for focus" & � 67 "stacks with thin and high contrast features such" & � 68 "as insect hairs etc, but will lead to increased noise." & return & return & � 69 "Expert options:" & return & � 70 "--ContrastWindowSize=s Window size for local contrast analysis." & return & � 71 "Default: 5, (must be bigger than 3)." & return � 72 buttons {"Ok"} 73end FUNC_ENF_PARAM 74---------------------------------------------------------------- 75on FUNC_Initialize_BP_PGB(titlebarmsg, topmsg, bottommsg) 76 tell application "BP Progress Bar" 77 launch 78 set title of window 1 to titlebarmsg 79 activate 80 show window 1 81 tell window 1 of application "BP Progress Bar" 82 tell progress indicator 1 83 set indeterminate to true 84 start 85 end tell 86 end tell 87 tell window 1 of application "BP Progress Bar" to tell text field 1 to set content to topmsg 88 tell window 1 of application "BP Progress Bar" to tell text field 2 to set content to bottommsg 89 end tell 90end FUNC_Initialize_BP_PGB 91---------------------------------------------------------------- 92---------------------------------------------------------------- 93on FUNC_quit_BP_PGB() 94 tell application "BP Progress Bar" to quit 95end FUNC_quit_BP_PGB 96---------------------------------------------------------------- 97---------------------------------------------------------------- 98-- function enfuse 99on FUNC_ENFUSE(dropped_on, ImageList) 100 101 102 -- set enfuse_additional_parameters to "--wExposure=1 --wSaturation=1 --wContrast=1" 103 set enfuse_additional_parameters to "" 104 ---- start images selection if dropped_on is false 105 if not dropped_on then 106 set ImageList to "" 107 set theImages to � 108 choose file with prompt � 109 "Select the image files of your choice" default location (path to pictures folder) � 110 of type {"JPEG", "TIFF", "PNG"} with multiple selections allowed without invisibles 111 repeat with OneImage in theImages 112 set OneImage to quoted form of POSIX path of OneImage 113 set testname to POSIX path of OneImage 114 -- we need this extension later 115 if (testname as text) ends with ".TIF" or (testname as text) ends with ".TIFF" then 116 set ImgExt to ".tif" 117 else 118 set ImgExt to ".jpg" 119 end if 120 121 set ImagePath to quoted form of POSIX path of OneImage --should do it only once but who cares 122 set ImageList to ImageList & OneImage & " " 123 end repeat 124 ---- end of images selection 125 end if 126 127 -- Find the working dir of the program, otherwise it will default to $HOME where ais and enfuse are not available 128 tell application "Finder" to get folder of (path to me) as Unicode text 129 set workingDir to POSIX path of result 130 131 ---- start of requesting align_image_stack parameters 132 set align_image_stack_parameters to "" 133 set get_going to "NOK" 134 repeat while get_going is "NOK" 135 display dialog "align_image_stack parameters" & return & return & � 136 "# default parameters set by this script:" & return & � 137 "-p file, output .pto => set to pano.pto" & return & � 138 "-a prefix align images => set to fused" & return & return & � 139 "# Other parameters can be set by you:" & return & � 140 "(Click Show Parameters to show possibilities)" & return & return & � 141 "Enter your additional parameters below. " default answer align_image_stack_parameters � 142 buttons {"Show Parameters", "Quit", "Ok"} default button "Ok" 143 set dialogResult to result 144 set align_image_stack_parameters to text returned of dialogResult 145 set choice to button returned of dialogResult 146 if choice = "Show Parameters" then FUNC_AIS_PARAM() 147 if choice = "Quit" then return -- exit script immediately 148 if choice = "Ok" then set get_going to "OK" 149 end repeat 150 --- end of requesting align_image_stack parameters 151 152 -- delete possible previous fused intermediate images (normally overwritten� 153 -- when there are more images from a previous run than need to be calculated, you get strange images 154 --tell application "Finder" 155 try -- use try to not display (error) dialog on non existing files 156 do shell script "rm " & workingDir & "fused*.tif" 157 end try 158 --end tell 159 160 161 ---- kick off align_image_stack and set barber pole 162 FUNC_Initialize_BP_PGB("Running align_image_stack", "Align_image_stack is aligning your images", "This will take some time. Please wait....") 163 do shell script "cd " & workingDir & "; " & workingDir & "align_image_stack" & " -a fused " & align_image_stack_parameters & " " & ImageList 164 FUNC_quit_BP_PGB() 165 ---- align_image_stack finished. stop barber pole 166 167 ---- start of requesting enfuse parameters 168 set get_going to "NOK" 169 repeat while get_going is "NOK" 170 display dialog "Enfuse additional parameters" & return & return & � 171 "Here you can specify your parameters." & return & � 172 "(Click Show Parameters to show possibilities)" & return & return � 173 default answer enfuse_additional_parameters buttons {"Show Parameters", "Quit", "Ok"} default button "Ok" 174 set dialogResult to result 175 set enfuse_additional_parameters to text returned of dialogResult 176 set choice to button returned of dialogResult 177 if choice = "Show Parameters" then FUNC_ENF_PARAM() 178 if choice = "Quit" then return -- exit script immediately 179 if choice = "Ok" then set get_going to "OK" 180 end repeat 181 --- end of requesting enfuse parameters 182 183 ----Ask filename of fused image and where it should be stored 184 set NewImgName to (choose file name with prompt "Specify the filename of your new fused image" default location (path to pictures folder)) 185 set NewImage to quoted form of POSIX path of NewImgName 186 set testname to POSIX path of NewImgName 187 -- file extensions are not treated case-sensitive within applescript 188 if (testname as text) ends with ".TIF" or (testname as text) ends with ".JPG" or (testname as text) ends with ".TIFF" or (testname as text) ends with ".JPEG" then 189 set NewImage to quoted form of POSIX path of testname 190 --display dialog NewImage 191 else 192 -- No image extension, so make it a tif 193 set testname to testname & ".tif" 194 set NewImage to quoted form of POSIX path of testname 195 --display dialog NewImage 196 end if 197 ---- kick off enfuse and set barber pole 198 FUNC_Initialize_BP_PGB("Running enfuse", "enfuse is merging your images", "This will take some time. Please wait....") 199 do shell script "cd " & workingDir & "; " & workingDir & "enfuse " & enfuse_additional_parameters & " -o " & NewImage & " " & workingDir & "fused*.tif" 200 FUNC_quit_BP_PGB() 201 ---- enfuse finished. stop barber pole 202 203 ---- Show fused image to the public 204 -- Stupid preview application is not scriptable so we need to shell out. 205 -- Next to that there is another stupidity: It's called Preview.app on Tiger and preview.app on Leopard. 206 do shell script "open /Applications/Preview.app " & NewImage 207 do shell script "open /Applications/preview.app " & NewImage 208 209end FUNC_ENFUSE 210-- end of function enfuse 211---------------------------------------------------------------- 212---------------------------------------------------------------- 213 214 215-- Main part of script 216-- Here does it all start 217-- Define some (initial) variables/properties 218global ImageList 219set ImageList to "" 220 221-- "open" handler triggered by drag'n'drop launch. 222-- This parts starts when a user drops files on it 223on open of finderObjects 224 global HUGIN_PATH 225 --set HUGIN_PATH to "/Applications/Hugin.app" 226 set HUGIN_PATH to "" 227 set ImageList to "" 228 repeat with OneImage in (finderObjects) -- in case multiple objects dropped on applet 229 --set pipo to quoted form of POSIX path of i as text 230 --display dialog pipo -- show file/folder's info 231 if folder of (info for OneImage) is true then -- process folder's contents too 232 repeat with OneImage in finderObjects 233 set OneImage to quoted form of POSIX path of OneImage 234 set testname to POSIX path of NewImgName 235 -- we need this extension later 236 if (testname as text) ends with ".TIF" or (testname as text) ends with ".TIFF" then 237 set ImgExt to ".tif" 238 else 239 set ImgExt to ".jpg" 240 end if 241 set ImagePath to quoted form of POSIX path of OneImage --should do it only once but who cares 242 set ImageList to ImageList & OneImage & " " 243 end repeat 244 end if 245 -- repeat with OneImage in finderObjects 246 set OneImage to quoted form of POSIX path of OneImage 247 set ImagePath to quoted form of POSIX path of OneImage --should do it only once but who cares 248 set ImageList to ImageList & OneImage & " " 249 -- end repeat 250 end repeat 251 -- run function enfuse 252 set dropped_on to true 253 FUNC_ENFUSE(dropped_on, ImageList) 254end open 255-- end of drag'n'drop launch 256 257-- This is the part that starts when user opens application by double-clicking it 258 259set ImageList to "" 260-- ask user what he/she wants 261set quit_app to false 262repeat until quit_app is true 263 display dialog "Click Enfuse to get going!" buttons {"about", "quit", "Enfuse"} default button "Enfuse" 264 set choice to button returned of result 265 if choice = "Enfuse" then 266 set dropped_on to false 267 FUNC_ENFUSE(dropped_on, ImageList) 268 else if choice = "about" then 269 FUNC_ABOUT() 270 else 271 return --user has chosen quit so quit script 272 end if 273end repeat 274end run