- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个图像,它使用暖色和冷色来表示 2D 空间中的深度。我希望能够将其绘制为 3D 曲面图,就像您在 Matlab 中所做的那样。我一直在玩 jzy3d 但我是 java 新手,所以我在做这件事时遇到了麻烦。理想情况下,就像在 Matlab 中一样,最好的方法是将其转换为灰度,然后绘制它,但我不知道如何做,所以任何帮助将不胜感激。
提前谢谢您。
最佳答案
您应该更详细地描述实际困难是什么。
但是,我很好奇(无论如何都想尝试一下 jzy3d)。所以我修改了SurfaceDemo.java用于加载图像并绘制 Hue 的值的示例各个像素。
它基本上可以归结为“更暖”和“更冷”的确切含义(没有双关语),但应该可以从色调值中得出这一点。 (注意:图像中的颜色只是绘图的颜色,与图像中的颜色无关。图像中的颜色仅决定绘图的高度在每个点绘制。)
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import org.jzy3d.analysis.AbstractAnalysis;
import org.jzy3d.analysis.AnalysisLauncher;
import org.jzy3d.chart.factories.AWTChartComponentFactory;
import org.jzy3d.colors.Color;
import org.jzy3d.colors.ColorMapper;
import org.jzy3d.colors.colormaps.ColorMapRainbow;
import org.jzy3d.maths.Range;
import org.jzy3d.plot3d.builder.Builder;
import org.jzy3d.plot3d.builder.Mapper;
import org.jzy3d.plot3d.builder.concrete.OrthonormalGrid;
import org.jzy3d.plot3d.primitives.Shape;
import org.jzy3d.plot3d.rendering.canvas.Quality;
public class BasicJzy3D extends AbstractAnalysis
{
public static void main(String[] args) throws Exception
{
BufferedImage image = ImageIO.read(new File("lena512color.png"));
AnalysisLauncher.open(new BasicJzy3D(image));
}
private final BufferedImage image;
BasicJzy3D(BufferedImage image)
{
this.image = image;
}
/**
* Returns the RGB value in the given image at the specified location,
* which is given in relative coordinates (between 0.0 and 1.0).
* Invalid coordinates will be clamped to the border
*
* @param image The image
* @param x The x coordinate
* @param y The y coordinate
* @return The RGB value
*/
private static int getRGB(BufferedImage image, double x, double y)
{
int w = image.getWidth();
int h = image.getHeight();
int ix = (int)(x * w);
int iy = (int)(y * h);
ix = Math.max(0, Math.min(w-1, ix));
iy = Math.max(0, Math.min(h-1, iy));
int rgb = image.getRGB(ix, iy);
return rgb;
}
/**
* Returns the hue for the given RGB color
* @param rgb The RGB color
* @return The hue
*/
private static float getHue(int rgb)
{
int r = (rgb >> 16) & 0xFF;
int g = (rgb >> 8) & 0xFF;
int b = (rgb >> 0) & 0xFF;
float hsb[] = new float[3];
java.awt.Color.RGBtoHSB(r, g, b, hsb);
float hue = hsb[0];
return hue;
}
static class ImageToValueMapper extends Mapper
{
private final BufferedImage image;
ImageToValueMapper(BufferedImage image)
{
this.image = image;
}
@Override
public double f(double x, double y)
{
int rgb = getRGB(image, x, y);
float hue = getHue(rgb);
return hue;
}
}
@Override
public void init()
{
Mapper mapper = new ImageToValueMapper(image);
// Define range and precision for the function to plot
Range range = new Range(0, 1);
int steps = 80;
// Create the object to represent the function over the given range.
final Shape surface = Builder.buildOrthonormal(
new OrthonormalGrid(range, steps, range, steps), mapper);
surface.setColorMapper(
new ColorMapper(new ColorMapRainbow(),
surface.getBounds().getZmin(),
surface.getBounds().getZmax(),
new Color(1, 1, 1, 1.0f)));
surface.setFaceDisplayed(true);
surface.setWireframeDisplayed(false);
// Create a chart
chart = AWTChartComponentFactory.chart(
Quality.Advanced, getCanvasType());
chart.getScene().getGraph().add(surface);
}
}
关于java - 在 Java 中将彩色图像转换为 3D 冲浪图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24267289/
我有一张地形图,我想在其中表示一些数据。请参见下图: 右侧用白色圈出的区域是独立于绘图其余部分的冲浪功能。我希望能够做的是改变配色方案。外部应该是灰度,内部应该是基于我与绘图分开的值的单一颜色。目前我
假设我有一个灰度(8 位)图像,并假设我有一个从同一图像创建的完整图像。图片分辨率为 720x576。根据 SURF 算法,每个 Octave 由 4 个盒式过滤器组成,它们由其边上的像素数定义。 第
我想使用 sift/surf 进行模板匹配。图像可以有 1...n 个目标。使用 surf/sift 只能提取一个目标。一种想法是将图像分割成多个片段,然后寻找筛选/冲浪匹配。它有效,但显然由于速度和
OpenCV 内置了许多匹配器,例如 KNN 和 BruteForce。我想知道某处是否存在某些功能,我可以计算两个功能之间的“成本”并自己进行匹配。基本上,我有两个 cv::Keypoint 对象,
我想冲浪这个功能: z=w.'*p %(close form) 哪个: w=[w0; w1] p=[cte0; cte1] 其中,w 是可变的,cte0 和 cte1 可以是任意数字。要使用 surf
我使用 Sift/Surf 和 ORB,但有时我会遇到 drawMatch 函数的问题。 错误在这里: OpenCV Error: Assertion failed (i2 >= 0 && i2 =
我尝试安装(很多次)OpenCV 3.0 for python 和额外的包(筛选、冲浪...)但我总是失败,我真的被卡住了。我在主环境中试过,然后在虚拟环境中试过, 这是我做的: cd git git
我是一名优秀的程序员,十分优秀!