Login  Register

Mixing custom and predefined features in FeatureStack of Advanced Weka Segmentation plugin

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Mixing custom and predefined features in FeatureStack of Advanced Weka Segmentation plugin

Dionysios Lefkaditis
Hello,

I am trying to build a custom feature vector using features provided by AWS and my own in order to classify/segment images using AWS in beanshell. My script is a blend of the two scripts presented in the "Scripting the Trainable Segmentation" page. The script runs ok, but I have problem on how to pass all the slices of custom ImageStack in to a new FeatureStack. As it is at the moment, it only gets the first slice. When I .show() the FeatureStack and I .getSize(), it only returns 1 slice. My script is pasted bellow, but for the sake of being short I have omitted all the classification part. I would greatly appreciate any input.

Thanks in advance

So here it is:

import ij.*;
import ij.process.*;
import trainableSegmentation.*;
import hr.irb.fastRandomForest.*;
 
// training input image (it could be a stack or a single 2D image)
image = IJ.openImage("/home/dionysis/fermi/media/data/CNH/cnh_multispectral/Denmark_field_1/original images/15/RGB.bmp");
IJ.run(image, "32-bit", "");
H = image.getHeight();
W = image.getWidth();

// corresponding binary labels
labels = IJ.openImage("/home/dionysis/fermi/media/data/CNH/cnh_multispectral/Denmark_field_1/original images/15/MOG.bmp");

//*** Custom features***
cam = NewImage.createByteImage("camera_number", W, H, 1, NewImage.FILL_WHITE);
IJ.run(cam, "32-bit", "");

// the FeatureStackArray contains a FeatureStack for every slice in our original image
featuresArray = new FeatureStackArray(image.getStackSize(), 1, 16, false, 1, 19, null);

features = new FeatureStack(image);
features.addGaussianBlur(20);
features.addLaplacian(5);

customstack = new ImageStack(features.getWidth(), features.getHeight());
customstack.addSlice("originalstd", features.getProcessor(1));
customstack.addSlice("gaussianstd", features.getProcessor(2));
customstack.addSlice("Laplacianstd", features.getProcessor(3));
customstack.addSlice("original", image.getProcessor().duplicate());
customstack.addSlice("camera", cam.getProcessor().duplicate());

customFeaturesImage2 = new ImagePlus("features_std&cust", customstack);
customFeaturesImage2.show();

stack2featstack = new FeatureStack(customFeaturesImage2);
stack2featstack.show();
print(stack2featstack.getSize());

featuresArray.set(stack2featstack, 0);
featuresArray.setEnabledFeatures(stack2featstack.getEnabledFeatures());

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Mixing custom and predefined features in FeatureStack of Advanced Weka Segmentation plugin

Ignacio Arganda-Carreras
Hello Dionysios,

You almost got it. The problem is you have to create the new FeatureStack
with the input image as parameter and the assign your custom ImageStack to
it. I only changed that and removed the last "setEnabledFeatures" call
because you can't use that method when creating your own features (it works
only with the regular ones).

The script should be like this:

import ij.*;
import ij.process.*;
import trainableSegmentation.*;
import hr.irb.fastRandomForest.*;

// training input image (it could be a stack or a single 2D image)
image =
IJ.openImage("/home/dionysis/fermi/media/data/CNH/cnh_multispectral/Denmark_field_1/original
images/15/RGB.bmp");
IJ.run(image, "32-bit", "");
H = image.getHeight();
W = image.getWidth();

// corresponding binary labels
labels =
IJ.openImage("/home/dionysis/fermi/media/data/CNH/cnh_multispectral/Denmark_field_1/original
images/15/MOG.bmp");

//*** Custom features***
cam = NewImage.createByteImage("camera_number", W, H, 1,
NewImage.FILL_WHITE);
IJ.run(cam, "32-bit", "");

features = new FeatureStack(image);
features.addGaussianBlur(20);
features.addLaplacian(5);

customstack = new ImageStack(features.getWidth(), features.getHeight());
customstack.addSlice("originalstd", features.getProcessor(1));
customstack.addSlice("gaussianstd", features.getProcessor(2));
customstack.addSlice("Laplacianstd", features.getProcessor(3));
customstack.addSlice("original", image.getProcessor().duplicate());
customstack.addSlice("camera", cam.getProcessor().duplicate());

customFeaturesImage2 = new ImagePlus("features_std&cust", customstack);
customFeaturesImage2.show();

// create new feature stack with the custom features
stack2featstack = new FeatureStack( image );
stack2featstack.setStack( customstack );

// the FeatureStackArray contains a FeatureStack for every slice in our
original image
featuresArray = new FeatureStackArray(image.getStackSize(), 1, 16, false,
1, 19, null);

// assign feature stack to array
featuresArray.set(stack2featstack, 0);

I hope it helps!

ignacio

On Thu, Mar 21, 2013 at 11:10 AM, Dionysios Lefkaditis <[hidden email]
> wrote:

> Hello,
>
> I am trying to build a custom feature vector using features provided by
> AWS and my own in order to classify/segment images using AWS in beanshell.
> My script is a blend of the two scripts presented in the "Scripting the
> Trainable Segmentation" page. The script runs ok, but I have problem on how
> to pass all the slices of custom ImageStack in to a new FeatureStack. As it
> is at the moment, it only gets the first slice. When I .show() the
> FeatureStack and I .getSize(), it only returns 1 slice. My script is pasted
> bellow, but for the sake of being short I have omitted all the
> classification part. I would greatly appreciate any input.
>
> Thanks in advance
>
> So here it is:
>
> import ij.*;
> import ij.process.*;
> import trainableSegmentation.*;
> import hr.irb.fastRandomForest.*;
>
> // training input image (it could be a stack or a single 2D image)
> image =
> IJ.openImage("/home/dionysis/fermi/media/data/CNH/cnh_multispectral/Denmark_field_1/original
> images/15/RGB.bmp");
> IJ.run(image, "32-bit", "");
> H = image.getHeight();
> W = image.getWidth();
>
> // corresponding binary labels
> labels =
> IJ.openImage("/home/dionysis/fermi/media/data/CNH/cnh_multispectral/Denmark_field_1/original
> images/15/MOG.bmp");
>
> //*** Custom features***
> cam = NewImage.createByteImage("camera_number", W, H, 1,
> NewImage.FILL_WHITE);
> IJ.run(cam, "32-bit", "");
>
> // the FeatureStackArray contains a FeatureStack for every slice in our
> original image
> featuresArray = new FeatureStackArray(image.getStackSize(), 1, 16, false,
> 1, 19, null);
>
> features = new FeatureStack(image);
> features.addGaussianBlur(20);
> features.addLaplacian(5);
>
> customstack = new ImageStack(features.getWidth(), features.getHeight());
> customstack.addSlice("originalstd", features.getProcessor(1));
> customstack.addSlice("gaussianstd", features.getProcessor(2));
> customstack.addSlice("Laplacianstd", features.getProcessor(3));
> customstack.addSlice("original", image.getProcessor().duplicate());
> customstack.addSlice("camera", cam.getProcessor().duplicate());
>
> customFeaturesImage2 = new ImagePlus("features_std&cust", customstack);
> customFeaturesImage2.show();
>
> stack2featstack = new FeatureStack(customFeaturesImage2);
> stack2featstack.show();
> print(stack2featstack.getSize());
>
> featuresArray.set(stack2featstack, 0);
> featuresArray.setEnabledFeatures(stack2featstack.getEnabledFeatures());
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>



--
Ignacio Arganda-Carreras, Ph.D.
Seung's lab, 46-5065
Department of Brain and Cognitive Sciences
Massachusetts Institute of Technology
43 Vassar St.
Cambridge, MA 02139
USA

Phone: (001) 617-324-3747
Website: http://bioweb.cnb.csic.es/~iarganda/index_EN.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html