Calling plugins (median filter) from javascript script

64 views
Skip to first unread message

Tamlyn Peel

unread,
Nov 15, 2016, 2:21:14 PM11/15/16
to Icy imaging
Hi,

Sorry another question.

Just in the process of automating all my image analysis. I originally started with protocol blocks to work out workflow (which is very handy), but I've moved to javascript in the end to hopefully make it easier. I can find examples of accessing plugins from javascript for some stuff (Kmeans, thresholding, spot tracking), but some others I can't quite get how to get my sequence in and/or the result out. For instance, median filter doesn't give a sequence back, but there's no 'getSequence' function listed:

importClass(Packages.plugins.spop.medianfilter.MedianFilter)

//Split channels
Chns = []
Chns[0] = SequenceUtil.extractChannel(origSeq, 0)
Chns[1] = SequenceUtil.extractChannel(origSeq, 1)
Chns[2] = SequenceUtil.extractChannel(origSeq, 2)
 
//Median filter//
median = new MedianFilter();

medianChns = []

for(i = 0; i < Chns.length; ++i){
    medianChns[i] = median.Median_filter_3D(Chns[i], 2)
}

I've also tried histogram equalisation (Packages.plugins.tlecomte.histogram.HistogramEqualization) with less success.

Is there a general way of handling these, or is the only option to harvest the original plugin code and modify it?

On a related note, is it sufficient to set a variable to nothing ("=[]") to unload that sequence from memory? Sorry, I'm learning javascript as I go.

Any help appreciated.

Cheers

Tamlyn

Tamlyn Peel

unread,
Jan 4, 2017, 8:54:04 AM1/4/17
to Icy imaging
Figured out how to do it, involving grabbing the open sequence viewer that contains the result. Not ideal as user could interfere, but works with a plugin not specifically written for scripts:

importClass(Packages.plugins.spop.medianfilter.MedianFilter)

//Open File//
// Open a file dialog and returns the file
f = FileDialog.open()

if (f == null) throw "User cancelled!"

origSeq = Loader.loadSequence(f)

//Extract channel
Chn = SequenceUtil.extractChannel(origSeq, 0)

//Close original file
origSeq.close()
origSeq = []


//Median filter//
median = new MedianFilter();

medianChn = []

//Next line necessary to ensure you get correct file handle
gui.closeAllViewers()

if (median.isHeadLess() == true) median.createUI() //First instance create UI to generate viewer
median.Median_filter_3D(Chn, 2)
//WAIT//
do {} while (gui.getActiveSequence() == null)
medianChn = gui.getActiveSequence()
gui.closeSequence(medianChn)

gui.closeAllViewers()

gui.addSequence(medianChn)

Stephane

unread,
Jan 5, 2017, 5:55:25 AM1/5/17
to Icy imaging
This one is tricky but well done to make it work ! It can be useful for people experiencing the same problem :)
Reply all
Reply to author
Forward
0 new messages