All Downloads are FREE. Search and download functionalities are using the official Maven repository.

boofcv.factory.segmentation.FactoryImageSegmentation Maven / Gradle / Ivy

Go to download

BoofCV is an open source Java library for real-time computer vision and robotics applications.

There is a newer version: 0.26
Show newest version
/*
 * Copyright (c) 2011-2015, Peter Abeles. All Rights Reserved.
 *
 * This file is part of BoofCV (http://boofcv.org).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package boofcv.factory.segmentation;

import boofcv.abst.segmentation.*;
import boofcv.alg.segmentation.fh04.SegmentFelzenszwalbHuttenlocher04;
import boofcv.alg.segmentation.ms.SegmentMeanShift;
import boofcv.alg.segmentation.slic.SegmentSlic;
import boofcv.alg.segmentation.watershed.WatershedVincentSoille1991;
import boofcv.struct.image.ImageBase;
import boofcv.struct.image.ImageType;

/**
 * Factory for {@link ImageSuperpixels} algorithms, which are used to segment the image into super pixels.
 *
 * @author Peter Abeles
 */
public class FactoryImageSegmentation {

	/**
	 * Creates a new instance of {@link SegmentMeanShift} which is in a wrapper for {@link ImageSuperpixels}.
	 *
	 * @see SegmentMeanShift
	 *
	 * @param config Configuration.  If null then defaults are used.
	 * @param imageType Type of input image.
	 * @param  Image type
	 * @return new instance of {@link ImageSuperpixels}
	 */
	public static ImageSuperpixels
	meanShift( ConfigSegmentMeanShift config ,  ImageType imageType )
	{
		if( config == null )
			config = new ConfigSegmentMeanShift();

		SegmentMeanShift ms = FactorySegmentationAlg.meanShift(config,imageType);

		return new MeanShift_to_ImageSuperpixels(ms,config.connectRule);
	}

	/**
	 * Creates a new instance of {@link SegmentSlic} which is in a wrapper for {@link ImageSuperpixels}.
	 *
	 * @see SegmentSlic
	 *
	 * @param config Configuration.
	 * @param imageType Type of input image.
	 * @param  Image type
	 * @return new instance of {@link ImageSuperpixels}
	 */
	public static ImageSuperpixels
	slic( ConfigSlic config , ImageType imageType )
	{
		SegmentSlic ms = FactorySegmentationAlg.slic(config, imageType);

		return new Slic_to_ImageSuperpixels(ms);
	}

	/**
	 * Creates a new instance of {@link SegmentFelzenszwalbHuttenlocher04} which is in a wrapper for {@link ImageSuperpixels}.
	 *
	 * @see SegmentFelzenszwalbHuttenlocher04
	 *
	 * @param config Configuration.  If null defaults are used.
	 * @param imageType Type of input image.
	 * @param  Image type
	 * @return new instance of {@link ImageSuperpixels}
	 */
	public static ImageSuperpixels
	fh04( ConfigFh04 config , ImageType imageType )
	{
		if( config == null )
			config = new ConfigFh04();

		SegmentFelzenszwalbHuttenlocher04 fh = FactorySegmentationAlg.fh04(config, imageType);

		return new Fh04_to_ImageSuperpixels(fh,config.connectRule);
	}

	/**
	 * Creates an instance of {@link WatershedVincentSoille1991}.  Watershed works better when initial seeds
	 * are provided.  In this adaptation of watershed to {@link boofcv.abst.segmentation.ImageSuperpixels} only the more basic algorithm
	 * is used where each local minima is a region, which causes over segmentation.  Watershed also only can process
	 * gray scale U8 images.  All other image types are converted into that format.
	 *
	 * @see WatershedVincentSoille1991
	 *
	 * @param config Configuration.  If null default is used.
	 * @param  Image type
	 * @return new instance of {@link ImageSuperpixels}
	 */
	public static ImageSuperpixels
	watershed( ConfigWatershed config , ImageType imageType )
	{
		if( config == null )
			config = new ConfigWatershed();

		WatershedVincentSoille1991 watershed = FactorySegmentationAlg.watershed(config.connectRule);

		Watershed_to_ImageSuperpixels ret = new Watershed_to_ImageSuperpixels(watershed,config.minimumRegionSize,config.connectRule);
		ret.setImageType(imageType);
		return ret;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy