a basic image tool v0.68 (use nconvert)

v0.68

now really ok with linux, (0.6 was not able to drag/resize in linux)

zip : https://github.com/littleneo/image_tools/zipball/master
fork: https://github.com/littleneo/image_tools

info (for v0.3 only)

.integration of nconvert (xnview features) and all of its features :
crop, resize, levels, rotate per degrees, copy from clipboard… billions of options. some of them are integrated in the ui but you can directly write any option in a textfield (XnNerds)

.selection box overlay for cropping : drag/resize the box to define the crop. (see video below)

. history of modification. create a first temp image from the original then from the temp a second temp, then from the second temp… etc.

. it only uses one image slot for all the temporary revision of an original so you got the my_original_image slot and my_original_image slot.tmp (in which you can cycle through the different temp revision)

. original images always stay safe and linked to their users

. directly paste an image from the clipboard. quick step from gimp, ps, alt-imp etc. should work in the other way too (soon).

you’ll need nconvert from here or a full xnview install :
http://www.xnview.com

bpy access
returns the active image, if an (or several) UV editor panel exists somewhere in you blender ui with an image displayed within. returns False if there’s several UVeditor are opened with different images.


import image_tools
img = image_tools.active()

nconvert features are available from the command line/scripts :
the following create a copy of img :

img = bpy.data.images['tranquille.jpg']
img.nconvert('-rotate 41 -rotate_flag smooth -autocontrast -noise reduce ')

http://thumbnails51.imagebam.com/15246/336d5e152454899.jpg

resize
http://thumbnails47.imagebam.com/15247/d253c9152460630.jpg
crop ans colors

mirror has been removed for now.

if you want to test, it’s not finished but this is safe and handy to my point of view. thanks for comment and c&c I’m not an image/texture guru so maybe you’ll have interesting ideas to share about what kind of feature would be helpful (but mm goal is not to rewrite ps of course)


img = image_tools.active() # returns the active image

methods so far : disabled for now in 0.4


img.rotate() # 180° 
img.rotate(-90) # to the left, works with rectangular images
img.mirror('Y') # as above but vertically
img.flip('X')
bpy.ops.image.rotate() # or mirror, flip etc operate a method on the 'active' image (visible in the UV editor)

DL (v0.3) :

updated 4 october : nconvert and history
updated 29 september 2011 thanks to Dustractor in this thread about bpy hooks.
functions are now available as image object methods :
improved a function that returns the displayed image in the uv editor, whatever the uv panel is displayed or not in the current screen. it acts a bit like woulld a bpy.context.active_image function do.

The second image shows an interesting result.
You can do this also with photos to see two different people from split images mirror right/mirror left.
It really shows how people are asymeterical.

The script still looks good & useful.
Thanks :slight_smile:

I needed this for uv of character body, head.
got the same kind of thing for uvmap if you want. as snippet for now.

updated to v0.2, see first post

incoming :

image_tools.nconvert(img,['-emboss'])

:eyebrowlift:

that would be cool if mac and linux users could tell me what are the default installation paths for
nconvert
http://www.xnview.com/en/download_nc.html
or similar tools

http://thumbnails51.imagebam.com/15246/336d5e152454899.jpg
http://thumbnails45.imagebam.com/15247/4d3d22152460611.jpg
resize
http://thumbnails47.imagebam.com/15247/d253c9152460630.jpg
crop ans colors
http://thumbnails53.imagebam.com/15247/a9db42152460636.jpg
v0.4

.integration of nconvert (xnview features) and all of its features :
crop, resize, levels, rotate per degrees, copy from clipboard… billions of options. some of them are integrated in the ui but you can directly write any option in a textfield

. history of modification. create a first temp image from the original then from the temp a second temp, then from the second temp… etc.

. it only uses one image slot for all the temporary revision of an original so you got the my_original_image slot and my_original_image slot.tmp (in which you can cycle through the different temp revision)

. original images always stay safe and linked to its users

. directly paste an image from the clipboard. quick step from gimp, ps, alt-imp etc. does not appear to work for my linux side, but ok for the dark side.

mirror has been removed for now.

if you want to test, it’s not finished but this is safe and handy to my point of view. thanks for comment and c&c I’m not an image/texture guru so maybe you’ll have interesting ideas to share about what kind of feature would be helpful (but mm goal is not to rewrite ps of course)

you’ll need nconvert from here or a full xnview install :
http://www.xnview.com

there is not any, macos applications are nothing more that an *.app file, which is not a file is directory that macos sees as a file but with right click opens it up as a directory. In this case nconvert is a binary that can installed anywhere and run from anywhere as long you use the terminal but of course that does not concern you. So you two options here either tell the user where to install nconvert or read the path yourself in python string of course given by the user.

If you want i can do this for you but one request cause I dont want to fragment code and create on version for windows, another for macos and another for linux, you could put it in the meta-androcto svn , just drop by in #blenderpython and ask meta-androcto permission , from there one you will need a sourceforge account and maybe download svn , but meta-androcto already use it on windows so he will be able to help you. Its pretty much a 10 minute setup and from there one each commit should take more than a second or two.

I have macos and ubuntu so i can cover the mac and linux side for you and make sure your addon runs smoothly on both platforms. Also uploading to meta-androcto svn ensure that your script is included to our builds which have several thousands downloads each as we included all scripts commited to the svn. Come and join us. Way cooler than media fire thats for sure. :wink:

I will have a go at fixing your addon.

this is neat would be cool if it would work on rendered layers/passes,<br>
like the curves does at the top of the tool panel. update instantly with needing to add from clipboard.

I have macos and ubuntu so i can cover the mac and linux side for you and make sure your addon runs smoothly on both platforms. Also uploading to meta-androcto svn ensure that your script is included to our builds which have several thousands downloads each as we included all scripts commited to the svn. Come and join us. Way cooler than media fire thats for sure.

hahahe ok np. I can’t today but be my guest, hack and integrate it if you can do that without my help (I’m littleneo also in wiki/svn).
for windows it lloks for nconvert in the addon folder and in c:\program files (should add for seven dunno if its c:\prog or prog files)

that would be cool if you add common locations (/usr/bin ? getting retarded about nux) ‘/’ paths are already ok.
this is line 53 : def nconvert_path() returns the nconvert path it has found, just add your own paths in the paths list
I’ll add a textfield for manual path but be my guest if you want to add it meanwhile.

holyenigma74 I will test on renders good idea. I don’t get it about “update instantly with needing to add from clipboard.” could you please tell me ? you mean “don’t generate temp image, replace source instantly” ?

Well I tried and failed this my code

def nconvert_path() :
    paths = [
        'C:/Program Files/XnView/nconvert.exe',
        'D:/Program Files/XnView/nconvert.exe'
        ]

    for path in paths :
        if isfile(path) : return path

    addons_paths = bpy.utils.script_paths('addons',user_pref=True) #,all=True) ?
    for path in addons_paths :
        if isfile(path + '/image_tools/nconvert.exe') :
            return clean(path) + '/image_tools/nconvert.exe'
    if sys.platform == "darwin":
        paths = ['Applications']

        for path in paths :
            if isfile(path) : return path

        addons_paths = bpy.utils.script_paths('addons',user_pref=True) #,all=True) ?
        for path in addons_paths :
            if isfile(path + '/NConvert/nconvert') :
                return clean(path) + '/NConvert/nconvert'
    return ''

it displays an “error” message but nothing beyond that so its impossible to debug. XnViewMP install does not work because it does not come with the nconvert command line tool, nconvert download provided that which i copy pasted in the application folder.

the

applications/nconvert/nconvert

command works fine in my terminal.

Maybe some of your other paths are not so mac friendly. Will have to take a full look to see exactly what you do with this script.

With all the excitement over the Cycles engine, I think adding a firefly removal/noise reduction tool would be a popular feature.

Now while the paint program I use does have some noise-reduction tools, having such a tool that uses some of the newer, more advanced de-noising techniques built into Blender would be quite convenient.

On the work so far, I wouldn’t be surprised if this gets used a lot, it looks quite nice in that you would have a suite of post-pro/texture editing tools like seen a 2D program inside Blender itself, combine this with the compositor and you just might be able to bypass external image editing programs completely in various cases.

my bad i did not understand your code so i screwed it up , I did not see at first that you appended the scripts path and assumed that nconvert was install inside your addon folder. So I copied there and changed the code. This is the new code

if sys.platform == "darwin":

        addons_paths = bpy.utils.script_paths('addons',user_pref=True) #,all=True) ?
        for path in addons_paths :
            if isfile(path + '/image_tools/NConvert/nconvert') :
                return clean(path) + '/image_tools/NConvert/nconvert'

I am still getting an error but the script unlike last time it triggers the command line tool . This is the error.

command :  -yflip -overwrite
** NCONVERT v5.91 (c) 1991-2011 Pierre-E Gougelet (May 12 2011/14:12:04) **
        Version for MacOS X  (All rights reserved)
** This is a freeware software (for non commercial use)

Usage : nconvert [options ...] file ...
     Type nconvert -help, for more information

error

maybe the path to the image is not compatible with macos.

I was wondering maybe it will also work if you add your path in the existing paths list, without the need to add a specific ‘if darwin’ test ?

maybe the path to the image is not compatible with macos.

it’s possible. but as it founds nconvert in your hd, I suppose most of the funcs work.

here is some debug you can do about paths :
I use app.tempdir to build the path for temp image :

&gt;&gt;&gt; bpy.app.tempdir
'C:\\DOCUME~1\\littleneo\\LOCALS~1\\Temp\\'

what darwin says ? this must return a valid path to a temp dir.

I also use the overwrite option of nconvert so it avoids 2 steps when ‘updating’ a temp image, maybe it’s related to linux file access policies and nconvert rights.
try comment line 637 :

        if args != '' : args += ' -overwrite'

and uncomment lines 646-647 :

        #if temp and isfile(rev.path) :
        #    os.remove(rev.path)

I have some funcs to test for folders and files (the common os func + blender relative path support) to the following command should returns True :

# open blender, load the addon, save the .blend with its default untitled.blend name
&gt;&gt;&gt; import image_tools
&gt;&gt;&gt; image_tools.isdir('//')
True
&gt;&gt;&gt; image_tools.isfile('//untitled.blend')
True

functions are located in fs_tools.py

you can also check the path property in the temporary collection. provided you just run a command (that failed as you reported above), a new field should have been written.

# the entire collection of temp images
temp_imgs = bpy.context.window_manager.imagetools.tempset
# temp image names are : &lt;original_image_name&gt;&lt;integer&gt;
# &lt;integer&gt; is the temp revision id
rev = temp_imgs['untitled0']
rev.path # should returns a valid path to $temp/untitled_tmp0.png

(arg I even don’t remember if its $a or a$ in bash :slight_smile: )
you will find the nconvert method, where the code fails with darwin line 635, it uses the same rev variable to retrieve the path that is/will be used TO the temp file.

some more :

image_tools.isfile(temp_imgs['untitled0'].path)
image_tools.isfile(bpy.data.images['tranquille.jpg'].filepath_raw)

I would try also to modify the options I gave to nconvert line 656
        #command.extend(['-out','png','-32bits','-clevel','9','-o',dest_path,sce_path])
        dest_path = '/usr/kilon/images/kilon.png'
        command.extend(['-o',dest_path,sce_path])

this should help, please let me know.

Now while the paint program I use does have some noise-reduction tools, having such a tool that uses some of the newer, more advanced de-noising techniques built into Blender would be quite convenient.

thanks, yes, denoise should be an ui option meanwhile you can do this :
in the image tools ui there’s a text field called ‘XnNerds’. paste this :
-noise reduce

here are (some of) the options nconvert supports* about image editing :
you can use these commands in the xnNerds textfield :
‘ok’ means the option has been integrated in the ui.

ok          -32bits           : Convert in 32bits
          -average size     : Average (3,5,7,9,11,13)
          -autocrop tol r g b : Auto Crop
ok          -autocontrast     : Auto Contrast
ok          -autolevels       : Auto Levels
ok          -levels b w       : Levels
ok          -balance r g b    : Color balance
          -binary dither    : Convert in Binary
              pattern : Ordered pattern
              floyd   : Floyd steinberg
              halft45 : Halftone 45
              halft90 : Halftone 90
              nodither : No dithering
ok          -blur percent     : Blur (1...100)
ok          -brightness value : Modify brightness (-100...100)
ok          -crop x y w h     : Crop
ok          -canvas w h pos   : Resize canvas
ok                  w h can be percent (ex: -resize 100% 200%)
?               or #x #y for offset
ok                    pos top-left, top-center, top-right
ok                    center-left, center, center-right
ok                    bottom-left, bottom-center, bottom-right
          -conbright value  : Modify brightness (-100...100)
ok          -colours num
ok          -colors num       : Convert in Indexed Colors (256, 216, 128, 64, 32, 16 or 8)
ok          -contrast value   : Modify contrast (-100...100)

          -dither           : Use Bayer dithering for conversion (Colors and Grey only)
          -deinter k n      : De-interlace
              k : even or odd
              n : dup or int
          -edetail          : Enhance detail
          -eedge percent    : Enhance edges (1...100)
          -edgedetect type  : Edge detect
              light/medium/heavy
          -efocus           : Enhance focus
          -emboss           : Emboss 
          -embossmore       : Emboss more
          -equalize         : Equalize
          -floyd            : Use floydSteinberg dithering for conversion (Colors and Grey only)
          -frestore         : Focus restoration
          -gamma value      : Modify gamma (0.01&lt;-&gt;5.0
          -gammasat value   : Modify gamma (0.01&lt;-&gt;5.0
          -gauss size       : Blur gaussian (3,5,7,9,11,13)
          -grey num         : Convert in Grey Scale (256, 128, 64, 32, 16, 8 or 4)
          -hls h l s        : Adjust Hue Lightness Saturation

          -log              : Apply logarithmic correction
          -maximum size     : Maximum filter (3,5,7,9,11,13)
          -medianb size     : Median Box filter (3,5,7,9,11,13)
          -medianc size     : Median Cross filter (3,5,7,9,11,13)
          -minimum size     : Minimum filter (3,5,7,9,11,13)



          -mosaic size      : Mosaic (1...64)
          -lens percent     : Lens (1...100)
          -noise reduce     : Reduce noise
          -noise type value 
              uniform   : Add uniform noise
              gaussian  : Add gaussian noise
              laplacian : Add laplacian noise
              poisson   : Add poisson noise
          -oil size         : Oilify (1...16)
          -ratio            : Keep the ratio for scaling
          -rtype            : Type of resampling
              quick    : Quick resize
              linear   : Bi-linear (linear)
              hermite  : Hermite
              gaussian : Gaussian
              bell     : Bell
              bspline  : Bspline
              mitchell : Mitchell
              lanczos  : Lanczos 3
          -rflag            : Flag for resizing
              incr   : Increase only
              decr   : Decrease only
              orient : Follow orientation
ok          -resize w h      : Scale width-height
ok              w h can be percent (ex: -resize 100% 200%)
ok          -rotate_flag      : Rotate flags
ok              smooth : Use smooth rotate
ok          -rotate degrees   : Rotate
          -swirl degrees    : Swirl (1...360)
          -tile size        : Tile (1...64)
ok          -xflip            : Flip horizontal
ok          -yflip            : Flip vertical
ok          -sharpen percent  : Sharpen (1...100)
          -shear            : Shear
          -slice            : Slice
          -soften percent   : Soften (1...100)
          -spread amount    : Spread (1...32)
          -waves wavelength phase amount : Waves
              wavelength   : (1.0 50.0)
              phase        : (0.0 360.0)
              amount       : (0.0 100.0)

          -posterize count  : Posterize (2...256)
          -normalize        : Normalize
          -solarize value   : Solarize (1...255)
          -swap type        : Swap component
              rbg   : RGB-&gt;RBG
              bgr   : RGB-&gt;BGR
              brg   : RGB-&gt;BRG
              grb   : RGB-&gt;GRB
              gbr   : RGB-&gt;GBR

          -sepia percent    : Sepia
          -negate           : Negate

          -text string      : Add a text
          -text_font name size  : Font name and size
          -text_color r g b : Text color
          -text_back r g b  : Text background color
          -text_flag pos    : Position of text
              top-left, top-center, top-right
              center-left, center, center-right
              bottom-left, bottom-center, bottom-right
          -text_pos x y     : Position or offset
          -text_rotation degrees : Rotation

          -truecolors
          -truecolours      : Convert in True Colors
  • there’s other switch about files management, files list batch processing, file format. someone has info about RAW camera format ? I don’t know this.

about linux and mac, this does not work with the script linked here, but this should be corrected soon.
atm there’s still something about user temp dir and symlinks, but the popen call has been corrected for mac and nux, it’s almost done.
so if you use a linux flavor or a bsd macos and want to test the work in progress version please tell me, thanks.

ok, should work on win, linux and mac now. many many thanks to kilon for patience and various tests
here is the link to the work version of the tool
http://blenderpython.svn.sourceforge.net/viewvc/blenderpython/259/scripts/addons_extern/image_tools/?view=tar

it well worth it. Making image editor a proper image editor it is something the needs to be done I think and your script is a big step towards that directions. I think the next step is for you to look for a replacement to nconvert with an open source library we can distribute freely and move this to blender trunk.

nconvert is free to use for educative, personnal and open-source project. (and very affordable if you’re a 3D studio.)
I send an email to the author about the licence, yes I don’t think nconvert can be packed with the addon.

ImageMagic could be an alternative (checking this)…

last progress, with a modal and a bit of BGL, there’s a draggable resizable crop selector.
still wip.