小编dtr*_*r43的帖子

图像中超像素的相邻和非相邻超像素

将图像分割成N个超像素后,我需要指定与一个超像素相邻或不相邻的超像素,并为所有超像素确定这种关系。

[L,NumLabels] = superpixels(A,200);
Run Code Online (Sandbox Code Playgroud)

如何为每个超像素指定相邻的超像素?

更新资料

我已经尝试了@Cris Luengo介绍的解决方案。但是出现了以下错误:

B=imread('H.jpg');
[L,N] = superpixels(B,200);
glcms=graycomatrix(L);
k=glcms(:,50);    %SupNum=50
[r,~]=find(k>0); 
aa=find(r==50);
r(aa)=[];
Run Code Online (Sandbox Code Playgroud)

错误

更新2 我按照MATLAB帮助中的说明进行操作,但对我不起作用。对于SupNum = 8,产生了以下结果:

输出量

matlab image-processing image-segmentation matlab-coder superpixels

7
推荐指数
1
解决办法
289
查看次数

绘图区域邻接图

图像具有超像素的质心,是否有用于绘制区域邻接图的MATLAB函数?

  L = superpixels(A, 200);
  K=regionprops(L, 'Centroid');  % Detemining centroid coordinates of each superpixels
Run Code Online (Sandbox Code Playgroud)

重心坐标 期望的输出

PS类似但不是精确的解决方案:

https://www.mathworks.com/matlabcentral/fileexchange/16938-region-adjacency-graph-rag

https://www.mathworks.com/matlabcentral/fileexchange/53614-image-graphs

matlab image-processing image-segmentation superpixels

6
推荐指数
1
解决办法
211
查看次数

Matlab中的并行循环和图像处理

我将实现基于简单线性反馈控制系统(LFCS)的显着物体检测方法。控制系统模型表示为以下方程式:

我想出了以下程序代码,但结果不应该是这样。具体来说,输出应类似于下图:

但是代码会产生以下输出:

代码如下。

%Calculation of euclidian distance between adjacent superpixels stores in variable of Euc

  A = imread('aa.jpg'); 
  [rows, columns, cnumberOfColorChannels] = size(A);
  [L,N] = superpixels(A,400);

  %% Determination of adjacent superpixels
  glcms = graycomatrix(L,'NumLevels',N,'GrayLimits',[1,N],'Offset',[0,1;1,0]);  %Create gray-level co-occurrence matrix from image
  glcms = sum(glcms,3);    % add together the two matrices
  glcms = glcms + glcms.'; % add upper and lower triangles together, make it symmetric
  glcms(1:N+1:end) = 0;    % set the diagonal to zero, we don't want to see "1 …
Run Code Online (Sandbox Code Playgroud)

matlab image image-processing image-segmentation superpixels

4
推荐指数
1
解决办法
153
查看次数

使用 Patch Embedding 进行视频处理的尺寸误差

我正在研究一种被提议用于视频分类的变压器模型。我的输入张量的形状为 [batch=16 ,channels=3 ,frames=16, H=224, W=224] ,为了在输入张量上应用补丁嵌入,它使用以下场景:

patch_dim = in_channels * patch_size ** 2
self.to_patch_embedding = nn.Sequential(
        Rearrange('b t c (h p1) (w p2) -> b t (h w) (p1 p2 c)', p1 = patch_size, p2 = patch_size),
        nn.Linear(patch_dim, dim),     ***** (Root of the error)******
    )
Run Code Online (Sandbox Code Playgroud)

我使用的参数如下:

 patch_size =16 
 dim = 192
 in_channels = 3
Run Code Online (Sandbox Code Playgroud)

不幸的是,我收到与代码中显示的行相对应的以下错误:

Exception has occured: RuntimeError
mat1 and mat2 shapes cannot be multiplied (9408x4096 and 768x192)
Run Code Online (Sandbox Code Playgroud)

我想了很多错误的原因,但我无法找出原因是什么。我该如何解决这个问题?

python pytorch einops

4
推荐指数
1
解决办法
119
查看次数

将地面真实掩模覆盖在图像上

在我的项目中,我从视频中提取了帧,在另一个文件夹中,我有每个帧的地面实况。\n我想将视频每帧的地面实况图像(在我的例子中,它是显着性预测地面实况)映射到其相关帧图像。作为示例,我有以下框架:

\n

\n

以下是真实掩码:

\n

\n

以下是真实值在框架上的映射。

\n

\n

我怎样才能做到这一点。另外,我有两个文件夹,每个文件夹内都有几个文件夹,每个文件夹内都有存储的帧。如何对这些批量数据进行操作?

\n

这是我的文件夹的层次结构:

\n

框架_文件夹:文件夹_1、文件夹_2、......

\n
\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 frames\n\xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 601   (601 and 602  and etc are folders that in the inside there are image frames that their name is like 0001.png,0002.png, ...)\n\xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 602\n       .\n       .\n       .\n\xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 700\n\n\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ground truth\n    \xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 601   (601 and 602  and etc are folders that in the inside there are ground truth masks that their name is like 0001.png,0002.png, ...)\n    \xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 602\n …
Run Code Online (Sandbox Code Playgroud)

python opencv pytorch

4
推荐指数
1
解决办法
744
查看次数

在matlab中检查没有for循环的数组中的成员资格

我想将此代码简化为无需 for 循环即可工作。

for i=1:N
    for j=1:N
        if ismember(j,A)

           PID(i,i)=TFP(i,j)+ PID(i,i);

        end
    end
end
Run Code Online (Sandbox Code Playgroud)

其中A是一个包含一些标签的矩阵。我之前TFP以 N*N 稀疏双精度的形式存储。所以,我想出了以下解决方案,但我找不到一种方法来实现成员资格条件(由?指定)。

PID = sum(TFP).*(?);
Run Code Online (Sandbox Code Playgroud)

可以不用循环实现吗?

matlab loops for-loop vectorization

3
推荐指数
2
解决办法
75
查看次数

基于超像素的图像边界

可以使用适当的索引手动指定位于图像边界的超像素(例如下面的示例用于第二个超像素L==2):

分割图像

选定的超像素

在某些情况下,需要以系统且非手动的方式指定位于图像边界中的所有那些超像素,类似于下面的图像:

没有边缘超像素的超像素图像

有什么标准方法可以做到吗?

matlab image-processing boundary image-segmentation superpixels

2
推荐指数
1
解决办法
73
查看次数

访问 PyTorch 中预训练模型中的特定层

我想从TimeSformer模型的某些块中提取特征,并且还想删除最后两层。

import torch
from timesformer.models.vit import TimeSformer

model = TimeSformer(img_size=224, num_classes=400, num_frames=8, attention_type='divided_space_time',  pretrained_model='/path/to/pretrained/model.pyth')
Run Code Online (Sandbox Code Playgroud)

模型打印如下:

TimeSformer(
  (model): VisionTransformer(
(dropout): Dropout(p=0.0, inplace=False)
(patch_embed): PatchEmbed(
  (proj): Conv2d(3, 768, kernel_size=(16, 16), stride=(16, 16))
)
(pos_drop): Dropout(p=0.0, inplace=False)
(time_drop): Dropout(p=0.0, inplace=False)
(blocks): ModuleList(  #************
  (0): Block(
    (norm1): LayerNorm((768,), eps=1e-06, elementwise_affine=True)
    (attn): Attention(
      (qkv): Linear(in_features=768, out_features=2304, bias=True)
      (proj): Linear(in_features=768, out_features=768, bias=True)
      (proj_drop): Dropout(p=0.0, inplace=False)
      (attn_drop): Dropout(p=0.0, inplace=False)
    )
    (temporal_norm1): LayerNorm((768,), eps=1e-06, elementwise_affine=True)
    (temporal_attn): Attention(
      (qkv): Linear(in_features=768, out_features=2304, bias=True)
      (proj): Linear(in_features=768, out_features=768, bias=True)
      (proj_drop): Dropout(p=0.0, …
Run Code Online (Sandbox Code Playgroud)

python deep-learning pre-trained-model pytorch

2
推荐指数
1
解决办法
1725
查看次数