Armand Posted April 29, 2015 Posted April 29, 2015 Hi,I've attached an example picture of a shape which i would like to calculate it's area. Let's say a user has marked this kind of shaped area on the screen and you need to run some calculations on it, like getting the area of it.- How would you go about this problem?Thanks in advance [u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!
Valuater Posted April 29, 2015 Posted April 29, 2015 "an example picture of a shape which i would like to calculate it's area." I see a rectangle... L x W = AreaTada!! 8)
SadBunny Posted April 30, 2015 Posted April 30, 2015 This is too vague. What do you mean exactly be area? The amount of black pixels? The amount of cm2? And what do you mean by "a user has marked this"? Does that mean you have the coordinates, dimensions and radii of the involved geometric shapes? (From the looks of it, two circles, a rectangle and a triangle...) Roses are FF0000, violets are 0000FF... All my base are belong to you.
Armand Posted April 30, 2015 Author Posted April 30, 2015 @Valuater great response, way to go!@SadBunny I have the whole coordinates and i need to calculate the area - by that i mean the number of pixels - I can convert these to whatever I want afterwards anyway.I can also see circles and rectangles and such but how to i make a code to analyze and calculate that?! [u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!
BrewManNH Posted April 30, 2015 Posted April 30, 2015 You'd be better off asking this question on a math or drafting forum rather than here. I don't see how this would pertain to AutoIt until you have the math or the algorithm needed to do it. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
jchd Posted April 30, 2015 Posted April 30, 2015 Given that in the example case one has several geometric 2nd degree shapes (one could be considered a circle but another is clearly an ellipsis) partly overlapping asymetrically, I bet my keyboard that the mathematical solution will be either very complex or too complex to be expressed in what maths call "elementary functions". For instance, just computing the common part between the ellipsis and the square (admit it is one) is awful.For the well-known goat and field problem (involving just two overlapping circles), see http://mathforum.org/library/drmath/view/51746.htmlIt was only in 1995 that a closed-form solution was discovered by Shepherd and van Eetvelt.I'd go for the pedestrian way which is guaranteed to work whatever image is given: examine the bitmap row after row and accumulate the black pixels. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
nitekram Posted April 30, 2015 Posted April 30, 2015 (edited) I may not know what I am talking about, but if the pic above is an example, and the colors are going to be that dramatic, then why not just count the pixels in the image (all the same color) then figure out how many pixels are in a inch squared, and then create a ratio to solve Actually after reading @jchd's last comment, I think we are on the same page Edited April 30, 2015 by nitekram spelling 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator
iamtheky Posted April 30, 2015 Posted April 30, 2015 same. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
Malkey Posted April 30, 2015 Posted April 30, 2015 (edited) This example has the black area of the image containing 258668 pixels = 181.078826909677 square centimetersexpandcollapse popup#include <GDIPlus.au3> #include <Array.au3> #include <WinAPI.au3> ; http://www.autoitscript.com/forum/topic/131661-gdi-image-file-to-2d-array-and-vice-versa/page__view__findpost__p__917176 Opt("MustDeclareVars", 1) Local $iW, $iH _GDIPlus_Startup() Dim $pixelarray, $iCounta, $iCountb Local $file_in = "area_thumb.png" ; "Bckgrnd.jpg" ; "image1-before.jpg" ; Local $file_out = "area_after.jpg" _ImageFileToNumberWhitePixels($file_in, $pixelarray) _GDIPlus_Shutdown() Func _ImageFileToNumberWhitePixels($filename, ByRef $aArray) Local $Reslt, $stride, $format, $Scan0, $hImage Local $v_Buffer, $width, $height Local $i, $j $hImage = _GDIPlus_ImageLoadFromFile($filename) $iW = _GDIPlus_ImageGetWidth($hImage) $iH = _GDIPlus_ImageGetHeight($hImage) $Reslt = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iW, $iH, $GDIP_ILMREAD, $GDIP_PXF32ARGB) ;Get the returned values of _GDIPlus_BitmapLockBits () $width = DllStructGetData($Reslt, "width") $height = DllStructGetData($Reslt, "height") $stride = DllStructGetData($Reslt, "stride") $format = DllStructGetData($Reslt, "format") $Scan0 = DllStructGetData($Reslt, "Scan0") For $i = 0 To $iW - 1 For $j = 0 To $iH - 1 $v_Buffer = DllStructCreate("dword", $Scan0 + ($j * $stride) + ($i * 4)) If Hex(DllStructGetData($v_Buffer, 1), 8) == "FFFFFFFF" Then $iCounta += 1 Else $iCountb += 1 EndIf Next Next _GDIPlus_BitmapUnlockBits($hImage, $Reslt) _GDIPlus_ImageDispose($hImage) ConsoleWrite("Width x Height = " & $iW & "x" & $iH & " = " & ($iW * $iH) & @LF) ConsoleWrite("WHite pixels + Non-white pixels = " & $iCounta & " + " & $iCountb & " = " & $iCounta + $iCountb & @LF) ConsoleWrite("Number of non-white pixels = " & $iCountb & @LF) ; Ref http://www.translatorscafe.com/cafe/units-converter/typography/calculator/pixel-%28X%29-to-centimeter-%5Bcm%5D/ ConsoleWrite("If 1 pixel = 0.02645833333333cm (x) x 0.02645833333333cm (y) , then" & @LF & $iCountb & " pixels = " & (0.2645833333333 * 0.2645833333333 * $iCountb) & " square centimeters " & @LF) Return EndFunc ;==>_ImageFileToNumberWhitePixelsEdit: Replaced 18107.8826909677 square centimeters Edited April 30, 2015 by Malkey Deciminal in wrong place. Definitely not a metre by a metre.
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