Since I kind of hit a wall with the standalone python script. Here is the
pygwy code I've written, based on the code posted on the pygwy tutorial.
I'm pretty close to a reasonable solution, but it won't be ideal, and it's
still a little too manual to be practical.
Some problems I'm having:
- the mark grains dialog doesn't seem to run in NONINTERACTIVE mode. In
interactive mode, while it remembers the slope value I'd like to use, it
does not remember the color for the mask. This is critical for my work (I
am trying to count the grains). Perhaps there's a line or two I could use
to change the color of the grains after they are marked?
- In general it seems really difficult to pass parameters to these
functions. I'm guessing there are some more direct functions I should be
using and so far I've been using GUI/front-end version. I tried to get
gwy_data_field_grains_mark_slope () to work, but apparently I don't have it
quite right. Either I'm a bit clueless (likely), or the function is for C
and hasn't made it into the python implementation.
- I have no idea how to get grain counts or statistics into a text file of
some sort. I've been relying on another program I have that is great for
export dot/grain counts, but lacks the image processing that gwyddion has.
- I have to load all the images I want to process in the Gwyddion GUI. I
am planning on doing this about 50 files at a time. Obviously a standalone
script would be ideal but in lieu of that, this console script is the best
option I have at the moment.
- export doesn't work if directory doesn't exist. this is trivial, and
probably could be fixed by some python code to look for the directory and
create it if it's missing.
START CODE
import gwyutils
# base name
basename = "c:\processed\sample%(sample_num)02d_marked_%(image_num)02d.png"
i = 0
num = 1
# get list of available containers
cons = gwy.gwy_app_data_browser_get_containers()
# iterate thru containers and datafields
for c in cons:
# get directory of datafields where key is key in container
dfields = gwyutils.get_data_fields_dir(c)
for key in dfields.keys():
# get processed datafield object
datafield = dfields[key]
# retrieve datafield number in container from key (for example
'/0/data')
datafield_id = key.split('/')[1]
# set palette of datafield
c.set_string_by_name("/%s/base/palette" % datafield_id, "Gray")
# call 'level' process module as non-interactive
gwy.gwy_process_func_run("level", c, gwy.RUN_NONINTERACTIVE)
# mark grains by threshold/slope
# if i == 0:
# gwy.gwy_process_func_run("grain_mark", c, gwy.RUN_INTERACTIVE)
# else :
# gwy.gwy_process_func_run("grain_mark", c, gwy.RUN_NONINTERACTIVE)
gwy.gwy_process_func_run("grain_mark", c, gwy.RUN_INTERACTIVE)
# request redraw before export
datafield.data_changed()
# export datafield to png, for the first time show export dialog
if i == 0:
gwyutils.save_dfield_to_png(c, key, basename %
{"sample_num":num,"image_num":i+1}, gwy.RUN_INTERACTIVE)
else :
gwyutils.save_dfield_to_png(c, key, basename %
{"sample_num":num,"image_num":i+1}, gwy.RUN_NONINTERACTIVE)
i += 1
# request redraw datawindows with datafields
datafield.data_changed()
On Wed, Oct 30, 2013 at 1:44 PM, Ramsey Hazbun <
[email protected]> wrote:
> A follow-up. I realize now that my compiled gwyddion is not working (the
> apt package did). I get the following error on start-up:
> Application and library version do not match: 2.33 vs. 2.31
> I imagine this is because I had the ubuntu package installed previously.
>
>
>
> On Wed, Oct 30, 2013 at 1:21 PM, Ramsey Hazbun <
> [email protected]> wrote:
>
>> I'm attempting to write a standalone python script to process about a
>> thousand images. I simply want to level and mark grains based on known
>> slope. From what I've seen and tried in pygwy this seems doable.
>>
>> I'm having a series of problems that have led me to this point.
>> - I started on windows. So no standalone gwy module for python
>> available. That much I read on the mailing lists. Not too worried since
>> I'm fine with using Linux. But less convenient.
>> - I went over to Ubuntu, but the gwyddion apt package (based on gwyddion
>> 2.31) doesn't seem to include the python gwy module.
>> - I installed the gtk devel package and compiled gwyddion 2.33 from
>> scratch using ./configure --with-python
>>
>> As you might of guessed I'm getting an error when I try to import the gwy
>> module in python:
>> ImportError: no module named gwy
>>
>> So what am I missing here? Let me know what additional info you might
>> need. I'm on Ubuntu 13.10.
>>
>> Also, thanks for all the hard work. I'm already assuming Yeti is going
>> to respond to me based on all the other messages I've read on these
>> gwyddion/python issues.
>>
>
>
------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
Gwyddion-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gwyddion-users