- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我尝试通过创建自己的插件在 imagej 中实现 Sobel 过滤器。我有有效的代码,但是它没有正确突出显示白色边缘。我已经尝试了一段时间了,但我只是不知道我做错了什么,或者我可能不完全理解索贝尔滤波器的植入,或者不理解数学。任何帮助将不胜感激。这是我的代码:
import ij.*;
import ij.process.*;
import ij.gui.*;
import java.util.*;
import java.awt.*;
import ij.plugin.filter.*;
import ij.process.*;
import java.lang.Math.*;
public class Filter_Plugin implements PlugInFilter {
String title = null;
int sobel_x[][] = {{-1,0,1},
{-2,0,2},
{-1,0,1}};
int sobel_y[][] = {{-1,-2,-1},
{0,0,0},
{1,2,1}};
int pixel_x;
int pixel_y;
public int setup(String arg, ImagePlus im) {
title = im.getTitle();
return DOES_8G;
}
public void run(ImageProcessor ip) {
int w = ip.getWidth();
int h = ip.getHeight();
ImageProcessor copy = ip.duplicate();
for (int x=1; x < w-2; x++)
{
for (int y=1; y < h-2; y++)
{
pixel_x = 1/6 * (sobel_x[0][0] * copy.getPixel(x-1,y-1)) + (sobel_x[0][1] * copy.getPixel(x,y-1)) + (sobel_x[0][2] * copy.getPixel(x+1,y-1)) +
(sobel_x[1][0] * copy.getPixel(x-1,y)) + (sobel_x[1][1] * copy.getPixel(x,y)) + (sobel_x[1][2] * copy.getPixel(x+1,y)) +
(sobel_x[2][0] * copy.getPixel(x-1,y+1)) + (sobel_x[2][1] * copy.getPixel(x,y+1)) + (sobel_x[2][2] * copy.getPixel(x+1,y+1));
pixel_y = 1/6 * (sobel_y[0][0] * copy.getPixel(x-1,y-1)) + (sobel_y[0][1] * copy.getPixel(x,y-1)) + (sobel_y[0][2] * copy.getPixel(x+1,y-1)) +
(sobel_y[1][0] * copy.getPixel(x-1,y)) + (sobel_y[1][1] * copy.getPixel(x,y)) + (sobel_y[1][2] * copy.getPixel(x+1,y)) +
(sobel_y[2][0] * copy.getPixel(x-1,y+1)) + (sobel_y[2][1] * copy.getPixel(x,y+1)) + (sobel_x[2][2] * copy.getPixel(x+1,y+1));
int val = (int)Math.sqrt((pixel_x * pixel_x) + (pixel_y * pixel_y));
if(val < 0)
{
val = 0;
}
if(val > 255)
{
val = 255;
}
ip.putPixel(x,y,val);
}
}
}
}
最佳答案
您的计算中有一个错误:您仅将第一个被加数(即矩阵的左上角)乘以 1/6。通过消除这个因素,我得到了以下适合我的代码:
import ij.*;
import ij.process.*;
import ij.gui.*;
import java.util.*;
import java.awt.*;
import ij.plugin.filter.*;
import ij.process.*;
import java.lang.Math.*;
public class Filter_Plugin implements PlugInFilter {
String title = null;
int sobel_x[][] = {{-1,0,1},
{-2,0,2},
{-1,0,1}};
int sobel_y[][] = {{-1,-2,-1},
{0,0,0},
{1,2,1}};
int pixel_x;
int pixel_y;
public int setup(String arg, ImagePlus im) {
title = im.getTitle();
return DOES_8G;
}
public void run(ImageProcessor ip) {
int w = ip.getWidth();
int h = ip.getHeight();
ImageProcessor copy = ip.duplicate();
for (int x=1; x < w-2; x++) {
for (int y=1; y < h-2; y++) {
pixel_x = (sobel_x[0][0] * copy.getPixel(x-1,y-1)) + (sobel_x[0][1] * copy.getPixel(x,y-1)) + (sobel_x[0][2] * copy.getPixel(x+1,y-1)) +
(sobel_x[1][0] * copy.getPixel(x-1,y)) + (sobel_x[1][1] * copy.getPixel(x,y)) + (sobel_x[1][2] * copy.getPixel(x+1,y)) +
(sobel_x[2][0] * copy.getPixel(x-1,y+1)) + (sobel_x[2][1] * copy.getPixel(x,y+1)) + (sobel_x[2][2] * copy.getPixel(x+1,y+1));
pixel_y = (sobel_y[0][0] * copy.getPixel(x-1,y-1)) + (sobel_y[0][1] * copy.getPixel(x,y-1)) + (sobel_y[0][2] * copy.getPixel(x+1,y-1)) +
(sobel_y[1][0] * copy.getPixel(x-1,y)) + (sobel_y[1][1] * copy.getPixel(x,y)) + (sobel_y[1][2] * copy.getPixel(x+1,y)) +
(sobel_y[2][0] * copy.getPixel(x-1,y+1)) + (sobel_y[2][1] * copy.getPixel(x,y+1)) + (sobel_x[2][2] * copy.getPixel(x+1,y+1));
int val = (int)Math.sqrt((pixel_x * pixel_x) + (pixel_y * pixel_y));
if(val < 0)
{
val = 0;
}
if(val > 255)
{
val = 255;
}
ip.putPixel(x,y,val);
}
}
}
}
你看过Stephan Preibisch's Sobel Filter Plugin吗?作为引用?
也许您应该将输出设为 32 位浮点图像,而不是截断 0 和 255 处的值。
关于java - 在 ImageJ 中实现 Sobel 过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19331515/
我尝试用java实现Sobel边缘检测。它有点有效,但我收到了很多看似随机的噪音...... 我将图像加载为 BufferedImages 并首先将其转换为灰度图像(通过我在网上找到的算法)。之后我计
我尝试在 Java 中实现 Sobel 运算符,但结果只是一些像素的混合。 int i, j; FileInputStream inFile = new FileInputStream
我有每个像素的 Sobel 算子的梯度。在我的例子中是 320x480。但是我怎样才能将它们与方向联系起来呢?例如,我打算绘制指纹方向图。那么,我该如何开始呢? 是将梯度分成 block (例如 16
我为 Sobel 运算符编写了一个用于边缘检测的类,但是当我使用示例图像时,我的边缘消失了。如果有人可以帮助我,我将不胜感激。 import java.awt.image.BufferedImage;
x-导数 Sobel 看起来是这样的: -1 0 +1 -2 0 +2 -1 0 +1 假设我的图像有两个样本看起来像这样(0=黑色,1=白色): 0 0 1 1 0 0 0 0
我正在使用图像上的索贝尔边缘检测进行作业。我目前正在努力进行渐变操作。编译时收到“二元运算符 '*' 的操作数类型错误”错误。我认为这可能是因为我将所有像素定义为字母,并且我不确定下一步应该是什么。任
我的 Sobel 边缘检测算子的输出很奇怪。这是我的代码: BufferedImage temp = img; float kernelx[][] = {{-1, 0, 1},{-2,
我想在我的 android 应用程序中使用 Sobel 运算符。但是我不明白如何使用一个像素。 int sobel_x[][] = {{-1, 0, 1}, {-2, 0, 2},
我想在图像上使用高斯模糊作为使用 sobel 边缘检测过滤器的预处理步骤。 我以前在灰度图像上有效地实现了 sobel 和高斯模糊运算符,但是,我从未尝试过在彩色图像上使用它们。 之前,我一直采用像素
对于嵌入式设计,我试图在不使用缓冲器的情况下在板上实现索贝尔边缘检测。即我直接从屏幕上阅读和写作。但是,我可以存储大约一两个图像宽度的数据以供以后引用。这是由于董事会规定的限制。但是我陷入了一些问题。
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
我试图理解 cv2.Sobel 中的 scale 参数.将 scale 设置为 1/8,我沿 x 轴得到如下输出: 但是对于 scale = 10 或 scale = 100,输出非常相似。 上面两幅
我正在使用 sobel 运算符通过 EmguCV 3.0(OpenCV 的 .NET 包装器)检测灰度图像中的边缘。 我使用的代码是 Image gray = new Image(@"C:\gray.
我正在使用 skimage 创建一个与此类似的 sobel 过滤器图像... 我想知道有没有办法锐化这个 sobel 滤镜图像?比如说,把那些比较淡的白线去掉,比如气球后面的淡淡的线条? 我用 Ski
OpenCV 文档说,(order == 0) 表示不会在这个方向上应用导数,即不会执行此内核的计算。 (Order == 1) 意味着这个方向的图像和内核只是一个简单的卷积。 但是 (order =
我想在文本中找到笔划的方向。 Sobel 算子如何用于此目的? 这张图显示的是dp,也就是梯度方向。我想知道如何应用 Sobel 运算符找到要选择的像素,从 p 到 q,沿着路径 sp,到找到边缘上的
我正在尝试对墙壁图像使用 sobel 过滤器,但它不起作用。 我的代码是: im=scipy.misc.imread('IMG_1479bis.JPG') im = im.astype('int32'
阅读一篇论文,我很难理解所描述的算法: 给定手写样本的黑白数字图像,裁剪出单个字符进行分析。由于这可以是任意大小,因此算法需要考虑到这一点(如果更简单,我们可以假设大小为 2^n x 2^m)。 现在
我正在尝试在水平和垂直方向上实现 sobel 运算符。但不知何故我得到了反向输出。我在下面附上的代码。对于水平蒙版 char mask [3][3]= {{-1,-2,-1},{0,0,0},{1,
我在使用 Sobel 算子进行边缘检测时遇到问题:它会产生太多假边缘,效果如下图所示。我正在使用 3x3 sobel 运算符 - 首先提取垂直然后水平,最终输出是每个滤波器输出的幅度。合成图像的边
我是一名优秀的程序员,十分优秀!