MATLAB叶片病灶切割遇到了问题,
切割时难以找到目标,
请问怎么才能正确切割?
clc
clear
close all
%读入图像
rgb=imread('Apple5 (2).jpg');
figure()
imshow(rgb)
title('原图像')
%不同彩色空间的每一分量进行不同的变换后合成
image=im2double(rgb);
%----------------使用imadjust-----------------------
rgb1=imadjust(image,[0.3,0.7],[0,1]);
figure()
imshow(rgb1)
title('调整对比度后')
%--------------使用直方图均衡化---------------------
img=histeq(image,256);
figure()
imshow(img)
title('使用直方图均衡化')
% 中值滤波
% 将图片分为R,G,B图片
R = img(:,:,1);
G = img(:,:,2);
B = img(:,:,3);
% 采用二维中值滤波函数medfilt2对图像滤波
R1 = medfilt2(R);
G1 = medfilt2(G);
B1 = medfilt2(B);
% 合并RGB三通道
RGB(:,:,1)=R1(:,:,1);
RGB(:,:,2)=G1(:,:,1);
RGB(:,:,3)=B1(:,:,1);
figure()
imshow(RGB)
title('中值滤波')
%转灰度图
I1=rgb2gray(RGB);
I=im2double(I1)
figure()
imshow(I)
title('灰度图')
%通过像素集合的区域增长
[g,NR,ST,TI]=regiongrow(I,158/255,55/255);
figure()
imshow(ST)
title('ST图像:种子点')
figure()
imshow(TI)
title('TI图像:通过阈值测试的点')
figure()
imshow(g)
title('分割出的图像:所有连接到种子点的像素的结果')
function [g, NR, SI, TI] = regiongrow(f, S, T)
%REGIONGROW Perform segmentation by region growing.
% [G, NR, SI, TI] = REGIONGROW(F, SR, T). S can be an array (the
% same size as F) with a 1 at the coordinates of every seed point
% and 0s elsewhere. S can also be a single seed value. Similarly,
% T can be an array (the same size as F) containing a threshold
% value for each pixel in F. T can also be a scalar, in which
% case it becomes a global threshold.
%
% On the output, G is the result of region growing, with each
% region labeled by a different integer, NR is the number of
% regions, SI is the final seed image used by the algorithm, and TI
% is the image consisting of the pixels in F that satisfied the
% threshold test.
% Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins
% Digital Image Processing Using MATLAB, Prentice-Hall, 2004
% $Revision: 1.4 $ $Date: 2003/10/26 22:35:37 $
f = double(f);
% If S is a scalar, obtain the seed image.
if numel(S) == 1
SI = f == S;
S1 = S;
else
% S is an array. Eliminate duplicate, connected seed locations
% to reduce the number of loop executions in the following
% sections of code.
SI = bwmorph(S, 'shrink', Inf);
J = find(SI);
S1 = f(J); % Array of seed values.
end
TI = false(size(f));
for K = 1:length(S1)
seedvalue = S1(K);
S = abs(f - seedvalue) <= T;
TI = TI | S;
end
% Use function imreconstruct with SI as the marker image to
% obtain the regions corresponding to each seed in S. Function
% bwlabel assigns a different integer to each connected region.
[g, NR] = bwlabel(imreconstruct(SI, TI));
有没有报错或者其他问题,发给我