PPI Posted January 27, 2016 Share Posted January 27, 2016 Hello, everybody. I am a professional in ATC (Air Traffic Control), and I have been pointed here to seek a solution for my problem. I need to work on large series of image files, all of the same size (they are frames of the same radar recording, actually). The operation that I need to perform on each image is quite simple, and can be carried out just with Paint. I need to cut and save a smaller portion of image, corresponding to a region of airspace where some event occurred. The dimensions of the smaller images and their position within the source frame (larger image) are obviously unchanged within the same series: I may want to specify a size and position at the beginning of the task (as the events to be analyzed never occur in the same region of airspace, for obvious reasons), but once the task has started, each smaller image would be cut-out with the same dimensions and from the same position within the source image. The steps are very simple: 1) input parameters (filename/path of the input series, and coordinates of the images to be cut-out) 2) open Paint 3) open the source image 4) in the Attributes, change (reduce) Width and Height to define what will be the right and lower borders of the final cut-out image 5) rotate 180° 6) again, reduce Width and Height to define what will be the left and upper borders of the final cut-out image 7) again, rotate 180° to put the image upside-up 8) save 9) increase image counter and loop from #3 until reaching end of the series 10) close Paint and exit It is obvious that, although simple, the above described steps cannot be repeated by hand if we are speaking of 300-400 frames of radar recording... I have been told that a relatively simple solution could be writing a script to drive Paint through the sequence of steps for the entire series. I must confess that, when I began to get a first look to this site, I was taken by dejection: in the past I wrote quite a number of programs in Assembler and Basic, but what I found here gave me the impression that I should take a degree in computer science before beginning... Any of you guys want to help me to begin with this task?... Many, many, MANY thanks in advance! Keep it simple, stupid. Link to comment Share on other sites More sharing options...
UEZ Posted January 27, 2016 Share Posted January 27, 2016 Your task can be easily done using GDIPlus rather than automating MS Paint. Give me some minutes to write a basic version. PPI 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
AutoBert Posted January 27, 2016 Share Posted January 27, 2016 @UEZ: I know you are answering like this. @PPI: I'm wondering you haven't tools your are needing for work. Or is this a small, private virtual ATC? PPI 1 Link to comment Share on other sites More sharing options...
UEZ Posted January 27, 2016 Share Posted January 27, 2016 @AutoBert @PPI try this: expandcollapse popup#include <File.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <EditConstants.au3> _GDIPlus_Startup() Global Const $hGUI = GUICreate("Test", 384, 120) Global Const $iBtn_Path = GUICtrlCreateButton("Path", 10, 10, 70, 40) Global Const $iInput_Path = GUICtrlCreateInput("", 90, 20, 160, 20) GUICtrlSetState(-1, $GUI_DISABLE) Global Const $iCombo_Ext = GUICtrlCreateCombo("JPG", 270, 20, 100, 21) GUICtrlSetData($iCombo_Ext, "BMP|PNG", "JPG") Global Const $iLabel_X = GUICtrlCreateLabel("X:", 20, 80, 20, 10) Global Const $iInput_X = GUICtrlCreateInput("0", 40, 76, 30, 20, $ES_NUMBER) Global Const $iLabel_Y = GUICtrlCreateLabel("Y:", 80, 80, 20, 10) Global Const $iInput_Y = GUICtrlCreateInput("0", 100, 76, 30, 20, $ES_NUMBER) Global Const $iLabel_W = GUICtrlCreateLabel("W:", 140, 80, 20, 10) Global Const $iInput_W = GUICtrlCreateInput("0", 160, 76, 30, 20, $ES_NUMBER) Global Const $iLabel_H = GUICtrlCreateLabel("H:", 200, 80, 20, 10) Global Const $iInput_H = GUICtrlCreateInput("0", 220, 76, 30, 20, $ES_NUMBER) Global Const $iBtn_Start = GUICtrlCreateButton("Start", 290, 60, 70, 40) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState() Global $sPath, $aFiles, $i, $iX, $iY, $iW, $iH While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GDIPlus_Shutdown() GUIDelete() Exit Case $iBtn_Path $sPath = FileSelectFolder("Select a path with images", "", 0, $hGUI) If @error Then MsgBox($MB_ICONWARNING, "Warning", "Operation has been aborted", 20, $hGUI) ContinueLoop EndIf GUICtrlSetState($iBtn_Start, $GUI_ENABLE) GUICtrlSetData($iInput_Path, $sPath) Case $iBtn_Start $aFiles = _FileListToArray($sPath, "*." & GUICtrlRead($iCombo_Ext), $FLTA_FILES, True) If @error Then MsgBox($MB_ICONWARNING, "Warning", "Operation has been aborted", 20, $hGUI) ContinueLoop EndIf $iX = GUICtrlRead($iInput_X) $iY = GUICtrlRead($iInput_Y) $iW = GUICtrlRead($iInput_W) $iH = GUICtrlRead($iInput_H) If BitOR($iW = 0, $iH = 0) Then MsgBox($MB_ICONWARNING, "Warning", "Please check width / height", 20, $hGUI) ContinueLoop EndIf For $i = 1 To $aFiles[0] Crop_Images($iX, $iY, $iW, $iH, $aFiles[$i]) Next MsgBox($MB_ICONINFORMATION, "Done", "Please check out provided folder for the results", 0, $hGUI) EndSwitch WEnd Func Crop_Images($iX, $iY, $iW, $iH, $sFilename) If FileExists($sFilename) Then Local $hImage = _GDIPlus_ImageLoadFromFile($sFilename) Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsDrawImageRectRect($hGfx, $hImage, $iX, $iY, $iW, $iH, 0, 0, $iW, $iH) _GDIPlus_ImageSaveToFile($hBitmap, StringTrimRight($sFilename, 4) & "_cropped.jpg") _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_ImageDispose($hImage) Return True EndIf Return False EndFunc PPI 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted January 27, 2016 Share Posted January 27, 2016 (edited) Just my input, I always do batch image processing with IrfanView, it has batch processing built right in, but when you want to automate or integrate further it has cmd parameters for everything make it easy to use with Autoit. Probably one of the larger benefits is that it supports more image types than GDIPlus. BTW: Tested UEZ code above and it worked really well. Edited January 27, 2016 by ViciousXUSMC PPI 1 Link to comment Share on other sites More sharing options...
PPI Posted January 27, 2016 Author Share Posted January 27, 2016 @AutoBert no "virtual" ATC: real airplanes, real radar, real airspace. You would be surprised by the amount of private resources that I (...and not only...) had to deploy from own wallet to do my job decently. Bureaucracy, bureaucracy... @UEZ and all the others: THANK YOU SO MUCH in advance I'm in a hurry, will be back in a couple of hours or so! Keep it simple, stupid. Link to comment Share on other sites More sharing options...
PPI Posted January 27, 2016 Author Share Posted January 27, 2016 @UEZ First of all (and again) THANK YOU very much for your effort and for the time you spent to it! And now, the sad part, a-ehm... Befor you mentioned it, I never heard a thing about something called GDIplus, and from the few things that Google returned, I'm not even sure about what it is... I went straight to the Paint+script solution because I've been told that, since Paint is already present, it would have been the most straightforward solution... Anyway, pardon me the utterly silly question [AUDIENCE LAUGHTERS ON]: how do I run the code you provided me? I suppose I should compile it to make it a .EXE, or do I need to have some interpreter installed?... [AUDIENCE LAUGHTERS OFF] @UEZ @ViciousXUSMC Quote Probably one of the larger benefits is that it supports more image types than GDIPlus What file formats does UEZ solution support? I work mostly with PNG and GIF images, the usual size being 2048x2048 (the size of an area radar display), is there any limitation with GDIplus?.. Folks, keep in mind that at the airport I work with two PCs, one running Windows 2000 and the other Windows XP, 95% of the work being carried out on the Win 2000 computer... The XP computer should be migrated to Windows 7, but don't ask me abut the times (again, bureaucracy...) while I am positively sure that I must prepare the next video before Feb 9th... Keep it simple, stupid. Link to comment Share on other sites More sharing options...
UEZ Posted January 27, 2016 Share Posted January 27, 2016 Supported GDI+ image formats: Quote The Image class provides methods for loading and saving raster images (bitmaps) and vector images (metafiles). An Image object encapsulates a bitmap or a metafile and stores attributes that you can retrieve by calling various Get methods. You can construct Image objects from a variety of file types including BMP, ICON, GIF, JPEG, Exif, PNG, TIFF, WMF, and EMF. I cannot tell you whether the script works properly with Win2000 but should work with with WinXP. Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
PPI Posted January 27, 2016 Author Share Posted January 27, 2016 23 minutes ago, UEZ said: Supported GDI+ image formats: I cannot tell you whether the script works properly with Win2000 but should work with with WinXP. @UEZ pardon me again, I know I'm sort of... stubborn... but I never used scripts before. How do I run the code you wrote for me? Do I have to compile it to an EXE? And how? Or does it run under an interpreter like my old programs in QuickBasic?... (I've to go to sleep right now, alarm clock in 6 1/2 hours! ) Keep it simple, stupid. Link to comment Share on other sites More sharing options...
UEZ Posted January 27, 2016 Share Posted January 27, 2016 Yes, compile the script and run it on the computer where the images are located. Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
PPI Posted January 28, 2016 Author Share Posted January 28, 2016 10 hours ago, UEZ said: Yes, compile the script and run it on the computer where the images are located. Okay, I surrender... I was tempted to write you in private to avoid public shame, but I thought that after all, forums should allow people to learn, so... Well, I googled the domain autoitscript.com with the search key "GDIplus compile OR compiler", and came to nothing useful, or at least nothing that I could understand... I use two PCs here, one running Win XP and the other running Win 2000. On the XP machine I don't have administrator rights and cannot install anything without previous authorization (again, bureaucracy... ) but I can run programs that does not require an installation process (like "portable" applications that can run from an USB stick or just copied to a local folder). On the Win 2000 machine I can do everything, but I understand that some most modern programs may not be compatible. So, one solution could be to compile the file "online", within the autoitscript.com website (assuming that the site offers such a service, but I didn't find it). Another solution coould be to get a compiler that does not need installation (to use under XP) OR that can be installed under Windows 2000. As a last resort, a compiler to install under XP, and I would have to push really hard the bean-counters to get the clearance to install it quickly... Uh, one last thing: I suppose that I would have to export the code you provided me to a file, in order to compile it, right?... How do I export it? Thank you SO much!! Keep it simple, stupid. Link to comment Share on other sites More sharing options...
junkew Posted January 28, 2016 Share Posted January 28, 2016 @PPI: as you are referring to a quick basic background probably an alternative is to switch to vbscript and wia library from microsoft https://msdn.microsoft.com/en-us/library/windows/desktop/ff486369%28v=vs.85%29.aspxhttps://msdn.microsoft.com/en-us/library/windows/desktop/ms630826(v=vs.85).aspx You then even can do it in Excel VBA without installing stuff FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
UEZ Posted January 28, 2016 Share Posted January 28, 2016 13 minutes ago, PPI said: Okay, I surrender... I was tempted to write you in private to avoid public shame, but I thought that after all, forums should allow people to learn, so... Well, I googled the domain autoitscript.com with the search key "GDIplus compile OR compiler", and came to nothing useful, or at least nothing that I could understand... I use two PCs here, one running Win XP and the other running Win 2000. On the XP machine I don't have administrator rights and cannot install anything without previous authorization (again, bureaucracy... ) but I can run programs that does not require an installation process (like "portable" applications that can run from an USB stick or just copied to a local folder). On the Win 2000 machine I can do everything, but I understand that some most modern programs may not be compatible. So, one solution could be to compile the file "online", within the autoitscript.com website (assuming that the site offers such a service, but I didn't find it). Another solution coould be to get a compiler that does not need installation (to use under XP) OR that can be installed under Windows 2000. As a last resort, a compiler to install under XP, and I would have to push really hard the bean-counters to get the clearance to install it quickly... Uh, one last thing: I suppose that I would have to export the code you provided me to a file, in order to compile it, right?... How do I export it? Thank you SO much!! Ok, I suggest to start with learning how to use AutoIt. Try first. Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
junkew Posted January 28, 2016 Share Posted January 28, 2016 and a working VBA example in Excel (Windows 7) replace directorynames / location of pictures Same should work in VBScript with some small modifications 'Make a reference to Microsoft Windows Image Aquisition library Sub test() Dim oIMG 'As ImageFile Dim oIP 'As ImageProcess 'Create the needed WIA objects Set oIMG = CreateObject("WIA.ImageFile") Set oIP = CreateObject("WIA.ImageProcess") 'Load your image oIMG.LoadFile "Y:\test_screenshot\wia.jpg" 'Rotate the image oIP.Filters.Add oIP.FilterInfos("RotateFlip").FilterID oIP.Filters(1).Properties("RotationAngle") = 90 'Crop the image oIP.Filters.Add oIP.FilterInfos("Crop").FilterID oIP.Filters(2).Properties("Left") = oIMG.Width \ 4 oIP.Filters(2).Properties("Top") = oIMG.Height \ 4 oIP.Filters(2).Properties("Right") = oIMG.Width \ 4 oIP.Filters(2).Properties("Bottom") = oIMG.Height \ 4 'Apply the image processing Set oIMG = oIP.Apply(oIMG) 'Save it to a new file Kill "Y:\test_screenshot\wia_new.jpg" oIMG.SaveFile "Y:\test_screenshot\wia_new.jpg" End Sub PPI 1 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
PPI Posted January 28, 2016 Author Share Posted January 28, 2016 1 hour ago, UEZ said: Ok, I suggest to start with learning how to use AutoIt. Try first. UEZ, I take an oath: after I'm finish with the task that they requested me (the image series, i.e. a video), I shall study how to use AutoIt, at least its fundamentals. I swear! But after, not now. Now I have to produce that series of images that is just the first step with 30 more to go before obtaining the final video: I lack the physical time to study it now. Could you please tell me where/how to compile your code? (apart from other things, the video "sampleavi.avi" doesn't play, I get an "Unknown error" message ) Keep it simple, stupid. Link to comment Share on other sites More sharing options...
mikell Posted January 28, 2016 Share Posted January 28, 2016 Easiest way : Right click the .au3 file containing UEZ' code >> Compile script Doc : [Help file > AutoIt > Using AutoIt > Compiling Scripts] Link to comment Share on other sites More sharing options...
PPI Posted January 28, 2016 Author Share Posted January 28, 2016 4 hours ago, mikell said: Right click the .au3 file containing UEZ' code WHAT .au3 file? Where is it?? Keep it simple, stupid. Link to comment Share on other sites More sharing options...
PPI Posted January 28, 2016 Author Share Posted January 28, 2016 9 hours ago, junkew said: and a working VBA example in Excel (Windows 7) replace directorynames / location of pictures Same should work in VBScript with some small modifications 'Make a reference to Microsoft Windows Image Aquisition library Sub test() Dim oIMG 'As ImageFile Dim oIP 'As ImageProcess 'Create the needed WIA objects Set oIMG = CreateObject("WIA.ImageFile") Set oIP = CreateObject("WIA.ImageProcess") 'Load your image oIMG.LoadFile "Y:\test_screenshot\wia.jpg" 'Rotate the image oIP.Filters.Add oIP.FilterInfos("RotateFlip").FilterID oIP.Filters(1).Properties("RotationAngle") = 90 'Crop the image oIP.Filters.Add oIP.FilterInfos("Crop").FilterID oIP.Filters(2).Properties("Left") = oIMG.Width \ 4 oIP.Filters(2).Properties("Top") = oIMG.Height \ 4 oIP.Filters(2).Properties("Right") = oIMG.Width \ 4 oIP.Filters(2).Properties("Bottom") = oIMG.Height \ 4 'Apply the image processing Set oIMG = oIP.Apply(oIMG) 'Save it to a new file Kill "Y:\test_screenshot\wia_new.jpg" oIMG.SaveFile "Y:\test_screenshot\wia_new.jpg" End Sub Thank you, thank you so much!! As soon as I understand how to compile, I wish to try your solution, too. But again, the same question I posted a few minutes ago for UEZ's code: where do I find the d*mn .au3 file?? Thank you again! Keep it simple, stupid. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 28, 2016 Moderators Share Posted January 28, 2016 PPI, Please calm down - as a pilot I prefer my ATC controllers to appear calm and in control! The file UEZ post4ed inpost #4 above is a script file - the text that can be compiled into a stand-alone executable. To do that you need to install AutoIt on a computer, copy the file from the forum (use the "pop-up" button at top-right to get a nice dialog) save the file somewhere (preferably with a .au3 extension, but that is not absolutely necessary) and then using the SciTE editor that is installed with AutoIt, load that file. Using the <Tools> menu of SciTE, select <Compile> to open the compilation dialog - the only thing you need to complete is the "target file name" and then press "Compile script". The executable will be created and you can then use it. Clearer? M23 PPI and Xandy 2 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
mikell Posted January 28, 2016 Share Posted January 28, 2016 This topic is becoming totally surrealist kylomas 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now