- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我是图像处理的新手,我试图使用这段代码检测垂直线-
image=imread('benzene.jpg');
BW = im2bw(image);
w1=[-1 2 -1 ; -1 2 -1 ; -1 2 -1];
g=(imfilter(double(BW),w1));
g=abs(g);
T=max(g(:));
g=g>=T;
imshow(g);
这是我的形象-
这是我执行操作后得到的-
所以我的问题是为什么我会得到这个输出?如果垂直双键被算作 2 条不同的垂直线,则有 10 条垂直线。另外,如果我想获得水平、垂直、45 和 -45 的所有线怎么办,我怎样才能使用所有 4 个掩码来获得一个输出?
最佳答案
我有一个简单的建议是检测梯度并确定边缘点的方向。请记住,方向是与边缘垂直的方向。所以,如果要找竖线,垂直于竖线的方向就是水平方向,相对于笛卡尔平面要么是180度,要么是-180度。因此,对于检测到的边缘点的每个方向,如果方向为 -180 度或 180 度,则将此位置的输出设置为 true
,否则为 false
。要检测梯度方向,请使用 imgradient
来自图像处理工具箱。我假设这是可用的,因为您同时使用了 imread
和 im2bw
并且它们都是该工具箱的一部分:
im = imread('http://i.stack.imgur.com/bdNOt.png');
tol = 5;
[~,ang] = imgradient(im);
out = (ang >= 180 - tol | ang <= -180 + tol);
imshow(out);
该代码使用一个名为 tol
的变量来定义您要检测的角度的公差,以考虑看起来垂直的噪声或边缘,但在计算角度时,它可能看起来不是.基本上,我们正在寻找角度在 180 度或 -180 度范围内的任何点。
这是我们得到的:
作为后处理的一种方式,您可以使用 bwareaopen
过滤掉面积低于一定数量的像素区域。利用垂直线的面积比其他像素大这一事实,您可以这样做:
out_filter = bwareaopen(out, 50);
我们得到:
现在如果你想检测水平线,你应该找到 -90 或 90 度的梯度方向。这是有道理的,因为那些水平线,垂直于水平线的方向确实是垂直的,即 -90 或 90 度。如果你想要斜线,如果你想要一条左倾线,寻找 45 度或 -135 度的角度和一条右倾线, -45 度或 135 度。我会让您弄清楚为什么这些角度确实代表了这些类型的线。
您提供的图像中没有任何水平线,所以我只查找斜线:
注意:由于量化误差,我不得不增加容差。
im = imread('http://i.stack.imgur.com/bdNOt.png');
tol = 20;
[~,ang] = imgradient(im);
out = (ang >= 45 - tol & ang <= 45 + tol) | (ang >= -135 - tol & ang <= -135 + tol);
out_filter = bwareaopen(out, 50);
imshow(out_filter);
还必须在这里增加容忍度:
im = imread('http://i.stack.imgur.com/bdNOt.png');
tol = 20;
[~,ang] = imgradient(im);
out = (ang >= 135 - tol & ang <= 135 + tol) | (ang >= -45 - tol & ang <= -45 + tol);
out_filter = bwareaopen(out, 50);
imshow(out_filter);
关于image - 图像中的线检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30934611/
当我调用 png.Decode(imageFile) 时,它返回类型 image.Image。但我找不到将其转换为 image.NRGBA 或 image.RGBA 的记录方式,我可以在其上调用 At
image/jpeg 和 image/png 包有 Decode 和 Encode 函数,可以读取和写入 jpeg 和 png 图像,但 image/gif 包没有 - 只有 Decode 和 Dec
我正在尝试从一系列任意的非调色板图像创建动画 GIF。为了创建调色板图像,我需要以某种方式想出一个调色板。 // RGBA, etc. images from somewhere else var f
我在今年夏天的空闲时间使用 Go 镜像包进行一些练习。 package main import ( "os" "image" "image/png" "image/co
关闭。这个问题需要debugging details .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 1年前关闭。 Improve this question 今天
我正在尝试在 TilePane 中列出图像。当我尝试创建图像 new ImageView("address"); 时出现错误,地址如下: "file:D:/Chrysanthemum.jpeg/" 以
我有一个用于为画廊选择图像的表单,我希望允许用户仅选择 jpg、gif 和 png 图像格式。 现在,为了测试,我将图像的扩展名更改为 .bmp,例如“image1.bmp”,当我在输入文件中单击以选
我有创建图像的代码:(m_img 是 javafx.scene.image.Image) Image m_img = new Image("file:" + p_Fil.getAbsoluteFile
假设我有一个这样的 8 位灰度图像: var pixels []byte = ... width := 100 height := 100 如何将其转换为实现 image.Image 的东西? 最佳答
这段代码是我在localhost:8088 URL上的索引/主页的一部分,如果我想将用户发送到url localhost:8088/image/1,我应该写href='image/{{$image->
我正在尝试对图像进行简单的裁剪。这是代码 from PIL.Image import Image def get_image_half(image, half="upper"): if hal
我在这个问题上花了一整天,但在堆栈溢出中没有看到答案! 我试过了但是没用: >> pil_image = Image.frombytes('RGBA', wand_image.size, wa
所以,我是那些以始终使用最新版本的浏览器而自豪的人之一(当然 Internet Explorer 除外 - 我说的不是那个浏览器)。 我遇到了 this awesome CSS3 website详细介
如果 image_tag 无法从 url 加载图像,我想呈现默认图像: 因此,如果 image_tag 无法从 url 加载图像: 然后呈现默认值: 这将生成结果 HTML: 关于image -
我正在创建一个类似横幅的组件,并将图像设置为组件的背景,但我无法让它工作。我尝试了网上发布的不同建议,但没有成功,目前我不确定我的错误是否在 react 代码中,或者是 webpack 没有正确加载文
如何解决 Dart 中的这种歧义错误。 import 'dart:io'; import 'package:flutter/material.dart'; import 'package:camera
Center( child: CachedNetworkImage( imageUrl: "http:/ sosme link he
设置 www.website.com/sds/(index.htm) 以便鼠标悬停在不同位置时显示图像。 出于某种原因,当您将鼠标悬停在蓝色气球上时,图像 2.jpg 和 3.jpg(在蓝色气球上来回
社交网络在共享 URL 时可以很好地从网站中提取标题和描述,但对于图像,仍然需要创建自定义元标记:property="og:image" name="twitter:image" itemprop="
我正在尝试写一个简短的,它将读取一个 PNG 文件,并将一个 channel 与另一个 channel (R,G,B) 交换作为可能的选择。 但是,我无法找到如何从 image.At(x,y) 返回的
我是一名优秀的程序员,十分优秀!