我正在构建一个可以识别空中图像的程序。
我可以加载图像并将其转换为黑白图像,但是我在尝试将像素值放入数组时遇到问题,因此我可以使用联合查找来链接白色像素的簇和黑色像素。
这是我到目前为止所做的:
import javafx.stage.FileChooser;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class Image {
public static void main(String args[])
{
new Image();
}
public Image()
{
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception ex) {
}
JFrame frame = new JFrame("Image");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //closes application properly
frame.add(new ImagePane());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
public class ImagePane extends JPanel {
private BufferedImage image;
private BufferedImage bwImage;
public ImagePane() {
try {
FileChooser fileChooser = new FileChooser();
image = ImageIO.read(new File("C:/Users/Connor/Desktop/image.jpg"));
this.image = image;
bwImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_BINARY);
this.bwImage = bwImage;
Graphics2D g2d = bwImage.createGraphics();
g2d.drawImage(image, 0, 0, this);
g2d.dispose();
} catch (IOException ex) {
ex.printStackTrace();
}
}
public Dimension getPreferredSize() {
Dimension size = super.getPreferredSize();
if (image != null) {
size = new Dimension(image.getWidth() * 2, image.getHeight());
}
return size;
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (image != null) {
int x = (getWidth() - (image.getWidth() * 2)) / 2;
int y = (getHeight() - (image.getHeight()));
g.drawImage(image, x, y, this);
x += image.getWidth();
g.drawImage(bwImage, x, y, this);
}
}
}
}
我希望获得如下输出:
{ 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1 },
{ 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
{ 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1 },
{ 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0 },
{ 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0 },
{ 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0 }
答案 0 :(得分:0)
所以这样做的方法是使用 MinHashLSH mh = new MinHashLSH().setNumHashTables(3).setInputCol("features")
.setOutputCol("hashes");
MinHashLSHModel model = mh.fit(dataset);
Dataset<Row> approxSimilarityJoin = model .approxSimilarityJoin(dataset, dataset, config.getJaccardLimit(), "JaccardDistance");
approxSimilarityJoin.show();
。
一个小代码示例如何解决这个问题:
BitSet
在此之后,您有一个BitSet,其中一个位表示白色,另一个位表示黑色。您现在可以根据需要对其进行数学分析。