问题描述
作为序言:这是我的第一个问题 - 我尽力使其尽可能清楚,但如果不符合要求的标准我会道歉。
As a preface: this is my first question - I've tried my best to make it as clear as possible, but I apologise if it doesn't meet the required standards.
作为夏季项目的一部分,我正在拍摄一张在冰晶中生长的内部融化图像的延时图像。对于这些图像中的每一个,我想测量所形成的图形的周长和面积。以下链接是我的一张图片的示例:
As part of a summer project, I am taking time-lapse images of an internal melt figure growing inside a crystal of ice. For each of these images I would like to measure the perimeter of, and area enclosed by the figure formed. Linked below is an example of one of my images:
我正在尝试使用的方法如下:
The method that I'm trying to use is the following:
- 加载图像,裁剪并转换为灰度
- 降低噪音的过程
- 查找边缘/周长
- 尝试连接边缘
- 用白色填充周长
- 使用regionprops测量面积和周长
- Load image, crop, and convert to grayscale
- Process to reduce noise
- Find edge/perimeter
- Attempt to join edges
- Fill perimeter with white
- Measure Area and Perimeter using regionprops
这是我正在使用的代码:
This is the code that I am using:
clear; close all;
% load image and convert to grayscale
tyrgb = imread('TyndallTest.jpg');
ty = rgb2gray(tyrgb);
figure; imshow(ty)
% apply a weiner filter to remove noise.
% N is a measure of the window size for detecting coherent features
N=20;
tywf = wiener2(ty,[N,N]);
tywf = tywf(N:end-N,N:end-N);
% rescale the image adaptively to enhance contrast without enhancing noise
tywfb = adapthisteq(tywf);
% apply a canny edge detection
tyedb = edge(tywfb,'canny');
%join edges
diskEnt1 = strel('disk',8); % radius of 4
tyjoin1 = imclose(tyedb,diskEnt1);
figure; imshow(tyjoin1)
正是在这个阶段我才挣扎。无论我如何使用形态结构元素,边缘都不会完全连接。也许有更好的方法来完成边缘? Linked是此代码输出的数字示例:
It is at this stage that I am struggling. The edges do not quite join, no matter how much I play around with the morphological structuring element. Perhaps there is a better way to complete the edges? Linked is an example of the figure this code outputs:
我尝试连接边缘的原因是我可以用白色像素填充周边,然后使用regionprops输出区域。我已尝试使用imfill命令,但似乎无法填充轮廓,因为在周边内有大量的暗区域要填充。
The reason that I am trying to join the edges is so that I can fill the perimeter with white pixels and then use regionprops to output the area. I have tried using the imfill command, but cannot seem to fill the outline as there are a large number of dark regions to be filled within the perimeter.
在这种情况下,是否有更好的方法可以获得其中一个融化数据的区域更合适?
Is there a better way to get the area of one of these melt figures that is more appropriate in this case?
作为背景研究:我可以使用下面的代码使这个方法适用于由白色背景上的黑色圆圈组成的简单图像。但是我不知道怎么编辑它来处理边缘定义不太清晰的更复杂的图像。
As background research: I can make this method work for a simple image consisting of a black circle on a white background using the below code. However I don't know how edit it to handle more complex images with edges that are less well defined.
clear all
close all
clc
%% Read in RGB image from directory
RGB1 = imread('1.jpg') ;
%% Convert RPG image to grayscale image
I1 = rgb2gray(RGB1) ;
%% Transform Image
%CROP
IC1 = imcrop(I1,[74 43 278 285]);
%BINARY IMAGE
BW1 = im2bw(IC1); %Convert to binary image so the boundary can be traced
%FIND PERIMETER
BWP1 = bwperim(BW1);
%Traces perimeters of objects & colours them white (1).
%Sets all other pixels to black (0)
%Doing the same job as an edge detection algorithm?
%FILL PERIMETER WITH WHITE IN ORDER TO MEASURE AREA AND PERIMETER
BWF1 = imfill(BWP1); %This opens figure and allows you to select the areas to fill with white.
%MEASURE PERIMETER
D1 = regionprops(BWF1, 'area', 'perimeter');
%Returns an array containing the properties area and perimeter.
%D1(1) returns the perimeter of the box and an area value identical to that
%perimeter? The box must be bounded by a perimeter.
%D1(2) returns the perimeter and area of the section filled in BWF1
%% Display Area and Perimeter data
D1(2)
推荐答案
您可能需要考虑活动轮廓。这将为您提供对象的连续边界,而不是曲面边缘。
You might want to consider Active Contours. This will give you a continous boundary of the object rather than patchy edges.
以下链接
一本书:
演示:
以及文件交换中的一些Matlab代码:
and some Matlab code on the File Exchange:http://www.mathworks.co.uk/matlabcentral/fileexchange/28149-snake-active-contour
以及指向des的链接关于如何实施它的说明:
and a link to a description on how to implement it: http://www.cb.uu.se/~cris/blog/index.php/archives/217
使用File Exchange上的实现,你可以得到这样的东西:
Using the implementation on the File Exchange, you can get something like this:
%% Load the image
% You could use the segmented image obtained previously
% and then apply the snake on that (although I use the original image).
% This will probably make the snake work better and the edges
% in your image is not that well defined.
% Make sure the original and the segmented image
% have the same size. They don't at the moment
I = imread('33kew0g.jpg');
% Convert the image to double data type
I = im2double(I);
% Show the image and select some points with the mouse (at least 4)
% figure, imshow(I); [y,x] = getpts;
% I have pre-selected the coordinates already
x = [ 525.8445 473.3837 413.4284 318.9989 212.5783 140.6320 62.6902 32.7125 55.1957 98.6633 164.6141 217.0749 317.5000 428.4172 494.3680 527.3434 561.8177 545.3300];
y = [ 435.9251 510.8691 570.8244 561.8311 570.8244 554.3367 476.3949 390.9586 311.5179 190.1085 113.6655 91.1823 98.6767 106.1711 142.1443 218.5872 296.5291 375.9698];
% Make an array with the selected coordinates
P=[x(:) y(:)];
%% Start Snake Process
% You probably have to fiddle with the parameters
% a bit more that I have
Options=struct;
Options.Verbose=true;
Options.Iterations=1000;
Options.Delta = 0.02;
Options.Alpha = 0.5;
Options.Beta = 0.2;
figure(1);
[O,J]=Snake2D(I,P,Options);
这篇关于MATLAB图像处理 - 查找图像的边缘和区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!