This new tool comes packaged with the SKMtools available for download from herehttp://forums.sketchucation.com/viewtop ... 77#p293677TIG (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.rbNeeds '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...

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?

thomthom wrote: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: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...

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 wrote: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.

Here's v1.1 viewtopic.php?p=294815#p294815It'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...]

CadFather wrote: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

I have looked at your '.jar' issue... I can reproduce it! IF I let a 'zip/unzip' application like AlZip or WinRar 'poach' the '.jar' file-type as one that it will open. If so then when Ruby tries to 'open' a '.jar' file instead of it 'executing' in Java [like it should], it 'opens' in the decompression application...

The solution = look at your WinRar settings and ensure '.jar' is NOT one of its file-types for opening...

thanks TIG, that's exactly what i did - (perhaps wasn't too clear in the edit)

one specu-question: could you, adjust the sampling rate/area of the script? suppose you didn't want so much precision, it could perhaps speed up the trimming process - having said that, the simplifier is well integratedonce the trim is achieved

CadFather wrote:thanks TIG, that's exactly what i did - (perhaps wasn't too clear in the edit)

one specu-question: could you, adjust the sampling rate/area of the script? suppose you didn't want so much precision, it could perhaps speed up the trimming process - having said that, the simplifier is well integratedonce the trim is achieved

Sorry - didn't see the 'edit' ! It first has to 'get' all of the edges of the solid/transparent areas - it's 'easier' to draw all of the edges as boundaries to these pixels - this is the most complex outline - a Factor 2 simplification will often improve the steppiness of these edges, BUT it can trim small solid areas or leave small transparent areas... Most of the time in the initial processing is finding which edge bits get faces or 'holes' and of course therefore which are part of which 'loops'... The 'simplifier' works on the face perimeter loops once they are made - it's much easier than trying to decide which edges could be the loops initially... You will have seen that the simplifier at Factor 2 reprocesses the faces' loops quite quickly... I can see how to easily recast the code to allow simplification before processing

CadFather wrote:i see.. still a pretty amazing feat.. in fact so are the images produced in the folder.. Thanks again

The Image's original 'image' file, 'edged' .png and a .dat file [01s] are put into the temporary folder [it is removed IF it's empty] made inside the SKP model's folder. If you answer 'No' when asked if you want to remove temporary files you can open/use them. I didn't automate this deletion because you might want the Image's 'image' file and/or the 'edged' .png. The .dat file does go but it's just a load of 0s and 1s !!! If you leave one of the dialogs open you can always read/copy it before it 'goes'

What am I doing wrong? I have a .png. I made it a component, selected it and then clicked on Image trimmer and get a warning 'Image trimmer: You selected an Image first.', so I exploded and tried again with same warning, I tried simplyfier and it works, but trimming does not, what am I doing wrong?

solo wrote:What am I doing wrong? I have a .png. I made it a component, selected it and then clicked on Image trimmer and get a warning 'Image trimmer: You selected an Image first.', so I exploded and tried again with same warning, I tried simplyfier and it works, but trimming does not, what am I doing wrong?

You don't use 'ImageTrimmer' on a 'Component' - you use it on a plain imported [unexploded] 'Image' - check in Entity Info to see what it is...After it's 'trimmed' that Image is copied as a Material applied to Faces inside a new Component... so then you can no longer 'trim' it, but of course you can 'simplify' the outlines later within the Component...

I don't know how use the plugin, i do this:1. I import a png file like image.2. I make a new component, its name the same like image.3. I make a new material with the png file with the same name, and i apply this material to the face inside the component.4. I select the image into SU and run the plugin.Nothing happens, only the plugin creates a folder named "TrimmedImages" in the same directory that Model file, it contains the png file.What i do bad?