从图像中提取道路 [英] Road Extraction from image

查看:88
本文介绍了从图像中提取道路的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做最后一年的项目,我从图像中提取道路。我拍摄图像,图像可以通过使用k-means聚类算法分割成三个不同的聚类,图像分成三个不同的聚类后我试图从该图像中选择最长连接的组件集群,但没有得到我想要的。我想删除该图像中的所有部分(道路除外)或者想要仅从该图像中看到道路。怎么办呢

o 输入图片

o 输出图像

o 预期输出

i am doing project of final year in that i Extract road from image .in that i take image , image can be segment into three different cluster by using k-means clustering algorithm that image divide into three different cluster after i tried to select longest connected component cluster from that image but not getting what i want .i want to delete all the portion from that image (Except Road)or want to visible only road from that image . how can do that
o input image
o output image
o Expected Output

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class Kmeans1 {
	BufferedImage image_temp;
	boolean not_terminated;
	int loops, changedPixels;
	int[] histogram;
	static int count = 0;
	int[] lowerbounds = new int[3];
	static int g = 0;
	int[] lb = new int[3];
	int[] ub = new int[3];
	int[] mean = new int[3];
	BufferedImage imaged;
	BufferedImage thresholdimage, dilateimage;

	public Kmeans1(BufferedImage image, int bins, int[] histogram)
			throws IOException {
		this.histogram = histogram;
		initialize(image, bins);
		calcbounds();

		// / calculateMean(histogram);
		processImage(image, bins);
		imaged = returnimage();
		imageWrite();
		for (int j = 0; j < 3; j++) {
			System.out.println("LB" + j + "=" + lb[j] + " UB" + j + "=" + ub[j]
					+ " Means" + j + "=" + mean[j]);
		}
	}

	public void initialize(BufferedImage image, int bins) {
		image_temp = image;
		not_terminated = true;
		mean[0] = 173;
		mean[1] = 100;
		mean[2] = 112;
	}

	public int createmean(BufferedImage image, int i, int bins) {
		int pixelindex = 0;
		int sum = 0;
		int value = 0;
		for (int h = 0; h < image.getHeight(); h++) {
			for (int w = 0; w < image.getWidth(); w++) {
				try {
					pixelindex += 1;
					if (pixelindex % bins == i) {
						Color rgb = new Color(image.getRGB(w, h));
						sum += rgb.getRed();
						value += 1;
						count++;
					}
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		return sum / value;

	}

	public void calcbounds() {
		for (int j = 0; j < 3; j++) {
			int lb1 = calculatelb(j);
			int ub1 = calculateub(j);
			lowerbounds[j] = lb1;
			lb[j] = lb1;
			ub[j] = ub1;
		}

	}

	private int calculatelb(int index) {
		int cMean = mean[index];
		int currentBound = 0;
		for (int i = 0; i < 3; i++) {
			if (cMean > mean[i]) {
				currentBound = Math.max((cMean + mean[i]) / 2, currentBound);
			} else {
			}
		}
		return currentBound;
	}

	private int calculateub(int index) {
		int cMean = mean[index];
		int currentBound = 255;
		for (int i = 0; i < 3; i++) {
			if (cMean < mean[i]) {
				currentBound = Math.min((cMean + mean[i]) / 2, currentBound);
			} else {
			}
		}
		return currentBound;
	}

	private void processImage(BufferedImage image, int bins) {
		int delta = 255 / (bins - 1);

		for (int h = 0; h < image.getHeight(); h++) {
			for (int w = 0; w < image.getWidth(); w++)

			{
				Color rgb = new Color(image.getRGB(w, h));
				int grey = rgb.getRed();

				for (int i = 0; i < 3; i++) {
					if (grey > lb[i] && grey < ub[i]) {
						g = i * delta;
						image_temp.setRGB(w, h, (new Color(g, g, g)).getRGB());
					} else {
						image_temp.setRGB(w, h, (new Color(g, g, g)).getRGB());
					}
				}
			}
		}
	}

	public BufferedImage returnimage() {
		return image_temp;
	}

	// BufferedImage img1=image_temp;
	public void imageWrite() throws IOException {
		// BufferedImage img1=image_temp;
		ImageIO.write(imaged, "jpg", new File("output.jpg"));
		System.out.println("image write completed");
	}

}
</code>
main method
<code> //
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.awt.image.Kernel;
import java.awt.image.ConvolveOp;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class design1 {
	static BufferedImage image;
	static int[] histogram = new int[256];

	public void makeHistogram() throws IOException {
		image = ImageIO.read(new File("input.png"));
		for (int i = 0; i < 256; i++)
			histogram[i] = 0;
		for (int h = 0; h < image.getHeight(); h++) {
			for (int w = 0; w < image.getWidth(); w++) {
				Color color = new Color(image.getRGB(w, h));
				int greyvalue = color.getRed();
				histogram[greyvalue] += 1;
			}
		}
	}

	public static void main(String[] args) throws IOException {

		new Kmeans1(image, 3, histogram);
	}

}

推荐答案

访问此处...



道路从图像中提取 [ ^ ]
visit here...

road Extraction from image[^]


这篇关于从图像中提取道路的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆