	public void run(String arg0) 
	{
		int nbima = WindowManager.getImageCount();
		if( nbima == 0 )
		{
			IJ.error( "Watershed 3D", 
					"At least one image needs to be open to run waterhsed in 3D");
			return;
		}
        String[] names = new String[ nbima ];
        String[] namesMask = new String[ nbima + 1 ];
        namesMask[ 0 ] = "None";
        for (int i = 0; i < nbima; i++) 
        {
            names[ i ] = WindowManager.getImage(i + 1).getShortTitle();
            namesMask[ i + 1 ] = WindowManager.getImage(i + 1).getShortTitle();
        }
        GenericDialog gd = new GenericDialog("Watershed 3D");
        int spot = 0;
        int seed = nbima > 1 ? 1 : 0;
        gd.addChoice( "Input image", names, names[spot] );
        gd.addChoice( "Image to seed from", names, names[seed] );
        gd.addChoice( "Mask", namesMask, namesMask[ nbima > 2 ? 3 : 0 ] );
        gd.addCheckbox( "Use priority queue", usePriorityQueue );
        gd.showDialog();
        if (gd.wasOKed()) 
        {
            spot = gd.getNextChoiceIndex();
            seed = gd.getNextChoiceIndex();
            int maskIndex = gd.getNextChoiceIndex();
            usePriorityQueue = gd.getNextBoolean();
            ImagePlus inputImage = WindowManager.getImage(spot + 1);
            ImagePlus seedImage = WindowManager.getImage(seed + 1);
            ImagePlus maskImage = maskIndex > 0 ? WindowManager.getImage( maskIndex ) : null;
            ImagePlus result = process( inputImage, seedImage, maskImage );
            ImageProcessor ip = result.getProcessor();
            ip.resetMinAndMax();
            result.setDisplayRange(ip.getMin(),ip.getMax());
            result.show();
        }
	}

	public void run(String arg0) 
	{
		int nbima = WindowManager.getImageCount();
		if( nbima == 0 )
		{
			IJ.error( "Watershed 3D", 
					"ERROR: At least one image needs to be open to run watershed in 3D");
			return;
		}
        String[] names = new String[ nbima ];
        String[] namesMask = new String[ nbima + 1 ];
        namesMask[ 0 ] = "None";
        for (int i = 0; i < nbima; i++) 
        {
            names[ i ] = WindowManager.getImage(i + 1).getShortTitle();
            namesMask[ i + 1 ] = WindowManager.getImage(i + 1).getShortTitle();
        }
        GenericDialog gd = new GenericDialog("Watershed 3D");
        int spot = 0;
        int seed = nbima > 1 ? 1 : 0;
        gd.addChoice( "Input image", names, names[spot] );
        gd.addChoice( "Image to seed from", names, names[seed] );
        gd.addChoice( "Mask", namesMask, namesMask[ nbima > 2 ? 3 : 0 ] );
        gd.addCheckbox( "Use priority queue", usePriorityQueue );
        gd.showDialog();
        if (gd.wasOKed()) 
        {
            spot = gd.getNextChoiceIndex();
            seed = gd.getNextChoiceIndex();
            int maskIndex = gd.getNextChoiceIndex();
            usePriorityQueue = gd.getNextBoolean();
            ImagePlus inputImage = WindowManager.getImage(spot + 1);
            ImagePlus seedImage = WindowManager.getImage(seed + 1);
            ImagePlus maskImage = maskIndex > 0 ? WindowManager.getImage( maskIndex ) : null;
            ImagePlus result = process( inputImage, seedImage, maskImage );
            ImageProcessor ip = result.getProcessor();
            ip.resetMinAndMax();
            result.setDisplayRange(ip.getMin(),ip.getMax());
            result.show();
        }
	}
