将图像分成宽度为N的块并计算每个块的边缘点Matlab [英] Dividing an image into N block in the width and calculating the edge points of each block Matlab

查看:329
本文介绍了将图像分成宽度为N的块并计算每个块的边缘点Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我在执行此代码后获得边缘点时,我试图将图像划分为宽度为N个不同的块:

Hello everyone I was trying to divide an image into N different blocks in the width after I performed this code to get its edge points:

Ioriginal = imread('sample.jpg') %read the image
Igray = rgb2gray(Ioriginal) %change it to gray scale
InoNoise = wiener2(Igray)  %remove noise from image
image = edge(InoNoise, 'prewitt') %get the edge points of the image

结果如下图所示:

the result is shown in this picture:

现在我要做的是将图像分成宽度中的N个相等的块并计算每个块的边缘点

Now what i want to do is dividing the image into N equal blocks in the width and calculate the edge points of each block

分割后,图像应按以下方式划分:

After the division, the image should be divided this way:

如果有人能真正帮助我做这部分,我真的很感激

I really appreciate if someone can really help me doing this part

谢谢你你

推荐答案

如果我理解你的问题,你想将检测到边缘的图像分解为 N 块,其中每个块的高度是图像的高度,而每个块的宽度计算为宽度 m ,其中 N * m =图像宽度。因此,每个块的宽度为图像宽度/ N 。请记住,您必须选择 N 的值,以便它可以被图像的宽度整除。你的图像有460列,所以我们可以选择任意数量的可以被10整除的块....所以让我们选择10个块。

If I understand your question correctly, you want to decompose the edge detected image into N blocks where the height of each block is the height of the image, while the width of each block is computed such that it is of width m, where N*m = width of image. Therefore, each block's width is width of image / N. Bear in mind that you must choose a value of N such that it is evenly divisible by the width of your image. Your image has 460 columns, and so we can choose any number of blocks that is divisible by 10 for example.... so let's choose something like 10 blocks.

分解图像的最简单方法是使用 mat2cell 。这采用2D矩阵并将矩阵分段。每个部分将存储在单元阵列中的单个元素中。因此,您需要确保每个块的高度相同,并且每个块的宽度使用我上面给出的公式。因此,您只需要这样做。我正在阅读您直接从StackOverflow发布的示例图像,但图像实际上传为RGB。我直接将它转换为二进制,以便我们得到一个实际的边缘图:

The easiest way to decompose your image would be to use mat2cell. This takes a 2D matrix and segments the matrix into pieces. Each piece would be stored in an individual element in a cell array. Therefore, you want to make sure that the height of each block is the same, and the width of each block is using that formula I gave you above. Therefore, you simply need to do this. I'm reading your example image that you posted directly from StackOverflow, but the image was actually uploaded as RGB. I converted it to binary directly so that we get an actual edge map:

N = 10; %// Declare total number of blocks
im = im2bw(imread('http://i.stack.imgur.com/ZvfoL.png')); %// Read in image
C = mat2cell(im, size(im,1), (size(im,2)/N)*ones(N,1));

C 将包含您的图像块,其中 C {idx} 将为您提供位于索引 idx 的图像块。如果你想把它变成一个3D数组,每个切片为你提供你想要的图像块,只需使用 cat 并在第三维中连接如下:

C will contain your image blocks, where C{idx} will get you the image block located at index idx. If you want to make this into a 3D array, where each slice gives you the image block you want, simply use cat and concatenate in the third dimension like so:

C_matrix = cat(3, C{:});

因此,要访问 idx 的块,只需 C_matrix(:,:,idx)

Therefore, to access the block at idx, simply do C_matrix(:,:,idx).

作为直观表示,让我们在图中显示每个块:

As a visual representation, let's display each block in a figure:

figure;
hold on;
for idx = 1 : N
    subplot(1,N,idx);
    imshow(C{idx}); %// Or imshow(C_matrix(:,:,idx));
end






这就是我得到的:


This is what I get:

基本上,每个块都放在窗口本身的单独图中,这就是我使用 subplot 的原因。您可以看到块之间存在白色间隙,可以正确显示图像中的每个分隔块。

Basically, each block is placed in a separate figure within the window itself, which is why I'm using subplot. You can see that there is a white gap in between the blocks, which properly shows you each separated block within your image.

祝你好运!

这篇关于将图像分成宽度为N的块并计算每个块的边缘点Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆