- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
给定下图:
我想确定哪些彩色区域被其他彩色区域包围或封闭。这可能如何计算?有没有办法创建一种显示此信息的树或表格?
示例:所有红色像素都在黄色区域内。
最佳答案
据我所知,没有内置函数可以执行此计算,但这里有一个关于如何获取所需信息的想法......
首先,您需要从上方获取 RGB 图像并将其转换为索引图像和颜色图。这是一种方法:
img = double(imread('nested_regions.png'))./255; % Load the RGB image
map = unique(reshape(img, [], 3), 'rows'); % Find the unique colors
labelImage = rgb2ind(img, map); % Get a labeled (i.e. indexed) image
nColors = size(map, 1);
接下来,您需要遍历每个标记区域,创建一个蒙版,然后使用 imfill
填充该蒙版中的任何“孔”。 .如果填充区域包含图像其余部分不包含的标签值,则这些区域完全包含在您填充的区域中。下面的代码使用 setdiff
执行此操作功能:
contains = cell(nColors, 1); % Storage for the contained region labels
str=' # | contains\n---+------------\n'; % String for displaying output
for iColor = 1:nColors
maskImage = (labelImage == iColor-1); % Mask of the current region
filledImage = imfill(maskImage, 'holes'); % Mask with holes filled
holeImage = (filledImage & ~maskImage); % Mask of the filled holes
contains{iColor} = setdiff(unique(labelImage(holeImage)), ...
unique(labelImage(~holeImage))).'; %.'
str = [str ' ' num2str(iColor-1) ' | ' num2str(contains{iColor}) '\n'];
end
imshow(labelImage, map, 'InitialMagnification', 60); % Display image
colorbar(); % with a colorbar
fprintf(str); % Create some formatted text output
运行上面的命令后,你会得到如下信息:
# | contains
---+------------
0 | 1 2 3 4 5 6 7 8 9
1 | 3 4 5 7 9
2 | 3 4 5 7 9
3 |
4 | 3
5 | 3 4
6 |
7 | 3 4 5
8 |
9 | 3 4 5 7
例如,红色像素(标记为区域 7)围绕标记区域 3、4 和 5(分别为灰蓝色、紫色和石灰)中的所有像素。有些区域不形成闭合轮廓,如 6(浅紫色)和 8(橙色)。区域 1(绿色)实际上并未完全包含在区域 2(蓝色)中,因为一两个绿色的虚假像素位于蓝色区域之外。
希望这能给你一些想法!
关于image - MATLAB 中有没有一种方法可以计算哪些离散图像区域包围或被另一个区域包围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36924378/
当我调用 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) 返回的
我是一名优秀的程序员,十分优秀!