• Login
sketchucation logo sketchucation
  • Login
πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

[Plugin] ImageTrimmer

Scheduled Pinned Locked Moved Plugins
364 Posts 58 Posters 228.1k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    TIG Moderator
    last edited by 16 Dec 2010, 15:48

    This new tool comes packaged with the SKMtools available for download from here
    http://forums.sketchucation.com/viewtopic.php?p=293677#p293677


    TIG (c) 2010 - 2016
    All Rights Reserved.
    THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
    WARRANTIES,INCLUDING,WITHOUT LIMITATION,THE IMPLIED WARRANTIES OF
    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.


    ImageTrimmer.rb


    Needs 'image_class.rb' and 'EdgeDetector.jar' [in the SKM_tools folder]


    Adds a new Tool 'ImageTrimmer':

    Menu > Tools > ImageTrimmer

    It takes a Selected Image [it must be a .png file] with transparent areas
    and it finds all of those areas' boundaries and it adds 'Edges' to them.
    It makes a new Component named after the Image containing faces with the
    Image applied as the Texture of a new Material with a matching name.
    All transparent Faces are removed as 'trimmed' outlines or 'holes'.
    The minimum size for a self-contained transparent area is 2x2 pixels -
    single transparent pixels or 'linear' pixels that are only a single pixel
    wide are merged into the solid areas.
    If the Image contains no suitable transparent pixels the Tool exits early
    with a warning, with no changes made.
    The processes show a % progress in the Command Line, it might take some
    time as there can be a lot of computation to do...
    The number of edges in a 'Trimmed' Component is effectively the number of
    pixels on the transparent areas' boundaries - this can run into several
    thousand short edges!
    An Instance of the new Component is placed at the Origin - it is initially
    made 'flat': you are asked if you want the new Component to 'Stand-up' -
    answer 'Yes' to rotate the Component's entities so it is vertical, or 'No'
    to leave it 'flat'.
    You are asked if you want to 'Flatten' the new Component's Material Texture
    PNG [remove transparency] so it will receive shadows - 'Yes' to convert...
    You are asked if you want to delete the original Image - answer 'Yes' to
    delete it, or 'No' to keep it.
    A sub-folder is made in the Model's folder called 'TrimmedImages'.
    The Tool uses it for the 'temporary' files needed to make its analysis and
    calculations. On completion you are prompted to delete these temporary
    files - you answer 'Yes' to delete them, or 'No' to keep them - these files
    are named after the original Image - e.g. 'StandingMan1.png' = the original
    'imagefile' as extracted from the Image, 'StandingMan1[Edges].png' = a copy
    of the 'imagefile' but processed so that there is a one pixel 'black'
    outline of the transparent areas and all other areas colored 'white'.
    If you chose to 'flatten' the png there will also be another file
    'StandingMan1[Flattened].png' = a copy of the 'imagefile' but processed so
    there are no transparent areas. You may find keeping these images useful ?
    There is a temporary 'data' file 'StandingMan1[Edges].dat' which contains
    '01' data used to construct the Sketchup Edges - this should be auto-erased
    whatever option you choose. If the 'TrimmedImages' folder is empty after
    the Tool completes it is deleted from the Model's folder.
    You are asked if you want to 'Simplify the Outline', 'Cancel' to leave the
    outline with the maximum 'pixelation', or enter a 'Factor' and press OK to
    simplify the outline.
    A very small 'Factor' will make few changes to the outlines [if any].
    A 'Factor' ~1 will leave the outlines almost unchanged.
    A 'Factor' ~2 [default] will usually simplify an outline quite acceptably.
    A 'Factor' ~3 will sometimes simplify the outline too much.
    A higher 'Factor' [5-10] will often make a very simplified outline that
    might only be acceptable in exceptional circumstances.
    This 'Simplification' is undoable. Remember that you can always Select a
    Component later and Simplify its outline - see below...
    The simplification processes show a % progress in the Command Line - the
    higher the 'Factor' you entered the quicker the outlines are simplified.

    It is one/two/three/four step undo-able depending on what you chose to do:
    undo the standing-up of the component, if changed.
    undo the deletion of the original Image, if deleted.
    undo simplification, if simplified.
    undo the 'ImageTrim' completely.

    The Tool is useful for auto-trimming transparent areas out of Images for
    'cardboard' cutouts of people etc. After the Component is made you might
    want to change its origin/axes to say its bottom center and make it into a
    'face-me' component etc so it always faces the camera etc...
    If you already have a Component using a transparent Material then save its
    Texture as an external Image file then Import as an Image, place over the
    original Component to resize appropriately and the run 'ImageTrimmer' on
    the Selected Image...

    Menu > Tools > ImageTrimmer-Simplifier

    After you have made 'Trimmed' Component you can simplify its outline by
    Selecting it and activating this tool.
    If you do not have an acceptable Selection a dialog warns, the tool exits.
    A dialog asks for the 'Factor, 'Cancel' to leave the outline unchanged or
    enter a 'Factor' and press OK to simplify the outline.
    A very small 'Factor' will make few changes to the outlines [if any].
    A 'Factor' ~1 will leave the outlines almost unchanged.
    A 'Factor' ~2 [default] will usually simplify an outline quite acceptably.
    A 'Factor' ~3 will sometimes simplify the outline too much.
    A higher 'Factor' [5-10] will often make a very simplified outline that
    might only be acceptable in exceptional circumstances.
    This 'Simplification' is undoable.
    The simplification processes show a % progress in the Command Line - the
    higher the 'Factor' you entered the quicker the outlines are simplified.
    Idea: if 'simplifying' with a Factor of 2 produces a result that's not
    quite what you want, don't 'undo it' be re-simplify the simplified version
    with a Factor of 2 again, you might get a surprisingly improved outline...


    Donations:
    By Paypal.com to info @ revitrev.org PayPalButton



    ImageTrimmer-Simplifier-Examples.PNG

    TIG

    1 Reply Last reply Reply Quote 0
    • B Offline
      Ben Ritter
      last edited by 16 Dec 2010, 16:31

      TIG, awesome and looking forward to trying it out. β˜€

      1 Reply Last reply Reply Quote 0
      • S Offline
        simon le bon
        last edited by 16 Dec 2010, 21:49

        Dear Tig,
        Even if I comment rarely, I have a great respect for your production and your generosity.
        Each tool you make, I feel how was we able to do without it.
        This is presently one more time the case.

        Thank yu so much,

        simon.

        1 Reply Last reply Reply Quote 0
        • S Offline
          shura
          last edited by 17 Dec 2010, 00:02

          This is just overwhelming. I was wanting this feature for so long... thank you TIG for making this happen!

          As I understand the prcedure, the way to trace a silhouette is to make an inverted transparency for it. With Flatten and Cleanup I get a nice result. Sadly I did'nt get Simplify Contours to work, maybe wrong angle?

          ( )

          jump.jpgjumpclose.jpg

          1 Reply Last reply Reply Quote 0
          • D Offline
            Dave R
            last edited by 17 Dec 2010, 01:04

            Very cool, TIG. Thank you.


            http://farm6.static.flickr.com/5090/5267654380_8f51fcd496.jpg

            Etaoin Shrdlu

            %

            (THERE'S NO PLACE LIKE)

            G28 X0.0 Y0.0 Z0.0

            M30

            %

            1 Reply Last reply Reply Quote 0
            • P Offline
              pilou
              last edited by 17 Dec 2010, 01:20

              Astonished package! πŸ‘ 😲 😎

              Frenchy Pilou
              Is beautiful that please without concept!
              My Little site :)

              1 Reply Last reply Reply Quote 0
              • M Offline
                mitcorb
                last edited by 17 Dec 2010, 04:04

                Out of the Blue!
                Thank you!

                I take the slow, deliberate approach in my aimless wandering.

                1 Reply Last reply Reply Quote 0
                • S Offline
                  srx
                  last edited by 17 Dec 2010, 09:11

                  That is great for png trees shadows. Thank you.

                  www.saurus.rs

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    thomthom
                    last edited by 17 Dec 2010, 09:17

                    This is great! It's been asked for for such a long time.
                    How about an option to simply the edges - make the resulting silhouette simpler?

                    You can use the Douglas-Peucker algorithm port I used in Edge Tools:
                    http://forums.sketchucation.com/viewtopic.php?f=323&t=24593#p210736

                    Thomas Thomassen β€” SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      TIG Moderator
                      last edited by 17 Dec 2010, 10:18

                      @thomthom said:

                      This is great! It's been asked for for such a long time.
                      How about an option to simply the edges - make the resulting silhouette simpler?
                      You can use the Douglas-Peucker algorithm port I used in Edge Tools:
                      http://forums.sketchucation.com/viewtopic.php?f=323&t=24593#p210736

                      Thanks for the tip... At the moment it slavishly follows every pixel!
                      This is only v1.0 so I'm sure there are lots of improvements possible.
                      My use of using one function specific small Java .jar executables reading 'ini' files to pass arguments etc seems to work better than I expected... So far in alphabetical order, there's...
                      Bumpmapper.jar and BumpmapperInverted.jar to make gray-scale bumpmap pngs from imagefiles.
                      EdgeDetector.jar that finds a given png's edges and makes the 'edged' version and a .dat file = 01's used by SUp.
                      Gifxtractor.jar that makes pngs of all frames in a given animated gif file.
                      Thumbnailer.jar that makes a 64x64 thumbnail of an image.
                      ThumbnailerRGB.jar that makes a 64x64 thumbnail of a color from its RGB values.
                      UnZipDirectory.jar that uncompresses zip files OR skm files.
                      ZipDirectory.jar that compresses zip files OR skm files in a given folder.
                      Any ideas for other similar 'jar' tools always welcomed - I only taught myself Java in the last week or two, specifically to do image manipulation parallel to Ruby, but I'm sure there are other possible uses too... πŸ€“

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        thomthom
                        last edited by 17 Dec 2010, 10:20

                        You've made a great deal of tools there. Too bad my apartment is such a mess still - don't get much time to look at all these new goodies.

                        Thomas Thomassen β€” SketchUp Monkey & Coding addict
                        List of my plugins and link to the CookieWare fund

                        1 Reply Last reply Reply Quote 0
                        • S Offline
                          shura
                          last edited by 17 Dec 2010, 10:25

                          With that .jar business I resign right away. just want to put another +1 here: simplifying edges? Oh yes please! (drooling)

                          1 Reply Last reply Reply Quote 0
                          • T Offline
                            TIG Moderator
                            last edited by 17 Dec 2010, 10:48

                            I had dallied with some outline simplification ideas... but brought v1.0 to market without that functionality as my brain hurt.
                            I'll think about it again - e.g. even a simple square hole 32x32 pixels currently has 128 edges when 4 would do!!
                            A square hole on the diagonal has 256 edges when 4 would do!!!
                            I'm sure I can clone some ideas from others' code πŸ˜‰ πŸ˜„

                            TIG

                            1 Reply Last reply Reply Quote 0
                            • T Offline
                              thomthom
                              last edited by 17 Dec 2010, 11:04

                              @tig said:

                              I'll think about it again - e.g. even a simple square hole 32x32 pixels currently has 128 edges when 4 would do!!
                              A square hole on the diagonal has 256 edges when 4 would do!!!
                              I'm sure I can clone some ideas from others' code πŸ˜‰ πŸ˜„

                              With the simplification algorithm I linked to, then those 128 edges should become 4. You feed it a set of points that form a curve (for separate each curve into sets and you get a simplified set.

                              Thomas Thomassen β€” SketchUp Monkey & Coding addict
                              List of my plugins and link to the CookieWare fund

                              1 Reply Last reply Reply Quote 0
                              • CadFatherC Offline
                                CadFather
                                last edited by 17 Dec 2010, 14:14

                                speechlessly amazing!

                                1 Reply Last reply Reply Quote 0
                                • T Offline
                                  TIG Moderator
                                  last edited by 17 Dec 2010, 15:12

                                  Here's v1.1 http://forums.sketchucation.com/viewtopic.php?p=294815#p294815
                                  It's got an 'outline simplifier' option added.
                                  This is also available a separate tool to simplify the outlines of existing ImageTrimmed components.
                                  See the notes for details...
                                  [Thanks to ThomThom and Douglas-Peucker fro the simplification algorithm ideas...]

                                  TIG

                                  1 Reply Last reply Reply Quote 0
                                  • T Offline
                                    TIG Moderator
                                    last edited by 17 Dec 2010, 15:46

                                    @cadfather said:

                                    not sure what happened but when run, the script opened edge 'detector.jar' file and there it stayed..
                                    it opened with winrar so will check this out

                                    You need to have Java enabled on you computer - it usually is...
                                    Did you extract most files into SKMtools subfolder as the instructions...
                                    The script doesn't open 'EdgeDector.jar' - rather it should 'execute' it as it's a very small app that does just one thing ?
                                    What OS system are you using ? XP ??
                                    What version of IE do you have ?
                                    What version of SUp ? I guess NOT 9.1 πŸ˜’

                                    TIG

                                    1 Reply Last reply Reply Quote 0
                                    • CadFatherC Offline
                                      CadFather
                                      last edited by 17 Dec 2010, 15:50

                                      not sure what happened but when run, the script opened edge 'detector.jar' file and there it stayed..
                                      it opened with winrar so will check this out

                                      EDIT: yes if winrar (i guess any other zipping app as well) is set to open jar files too - trimmer will run winrar -- uncheking the file association makes trimmer work fine

                                      1 Reply Last reply Reply Quote 0
                                      • CadFatherC Offline
                                        CadFather
                                        last edited by 17 Dec 2010, 15:51

                                        well TIG, with the likes of you, it feels like SU 10.2! πŸ˜†

                                        1 Reply Last reply Reply Quote 0
                                        • T Offline
                                          tomasz
                                          last edited by 17 Dec 2010, 19:48

                                          Thanks for the interesting plugin and the inspiration TIG!

                                          @tig said:

                                          I only taught myself Java in the last week or two

                                          Two weeks is not that much. I will give it a try!

                                          Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                                          1 Reply Last reply Reply Quote 0
                                          • 1
                                          • 2
                                          • 3
                                          • 4
                                          • 5
                                          • 18
                                          • 19
                                          • 1 / 19
                                          1 / 19
                                          • First post
                                            5/364
                                            Last post
                                          Buy SketchPlus
                                          Buy SUbD
                                          Buy WrapR
                                          Buy eBook
                                          Buy Modelur
                                          Buy Vertex Tools
                                          Buy SketchCuisine
                                          Buy FormFonts

                                          Advertisement