我有四种颜色的图像。每种颜色代表一个特定的物质阶段。我可以根据颜色对图像进行分割,然后计算分割后图像的周长。现在,我需要计算不同相之间的接触长度。 An example of the image is shown here。例如,蓝相和黄相之间的接触长度非常小,而蓝相和灰相之间具有显着的接触。
% aa is the image
oil = (aa(:,:,3)==255);
rock =(aa(:,:,2)==179);
gas =(aa(:,:,2)==255);
water =(aa(:,:,2)==0 && aa(:,:,3)==0);
O = bwboundaries(oil);
R = bwboundaries(rock);
G = bwboundaries(gas);
W = bwboundaries(water);
答案 0 :(得分:0)
一种蛮力方式将是遍历图像中的每个像素,并基于该像素值及其右侧的像素值,递增一个表示该相变触点长度计数的变量(如果存在)相变。然后对像素以下的值执行相同的操作。对图像中的每个像素(边缘条件除外)执行此操作。
一种更有效的方法是一次执行行和列,并在执行此操作时增加计数器。
或者您可以对图像制作多个矩阵,将它们移动一个像素,然后进行比较以查找最终产生二进制矩阵结果并简单地将这些结果二进制矩阵求和的相变
答案 1 :(得分:0)
这是我最终编写的最终代码。结果看起来正确。
% aa is the image
oil = (aa(:,:,3)==255);
rock =(aa(:,:,2)==179);
gas =(aa(:,:,2)==255);
water =(aa(:,:,2)==0 && aa(:,:,3)==0);
phases(1,:,:)=RockBW;
phases(2,:,:)=WaterBW;
phases(3,:,:)=OilBW;
phases(4,:,:)=GasBW;
outMat = ContactMatrix(phases);
ContactMatrix函数如下所示:
function [ContactMat] = ContactMatrix(phases)
%CONTACTMATRIX measure the contact area between diferent phases
% The output is a 2D matrix which shows the lengths
% Phase1, Phase2, Phase 3
%phase1 L1 L2 L4
%Phase2 L2 L3 L5
%Phase3 L4 L5 L6
% L1 is zero
% L2 is the contact area of Phase1 and Phase2
nph = size(phases,1);
imSize = size(phases(1,:,:));
xmax =imSize(2);
ymax = imSize(3);
% Idealy we need a check for all sizes :)
ContactMat = zeros(nph);
for i=1:1:nph
counts = zeros(1,nph);
dd2=bwmorph(squeeze(phases(i,:,:)),'dilate',1);
B = bwboundaries(dd2);
nB = size(B,1);
coefs=1:1:nph;
coefs(i)=[];
for j=1:1:nB
fd = B{j};
% Ignore the points at boundary of image
fd(fd(:,1)==1 | fd(:,1)==xmax | fd(:,2)==1 | fd(:,2)==ymax,:)=[];
nL = size(fd,1);
for k=1:1:nL(1)
%bufCheck=false(nph-1,1);
mat=fd(k,1) + (fd(k,2)-1)*xmax;
bufCheck = phases(coefs,mat);
counts(coefs)=counts(coefs)+bufCheck';
end
end
ContactMat(i,coefs)=counts(coefs);
end
ContactMat = 0.5*(ContactMat+ContactMat');
end