有人可以详细告诉我这个功能的每一行吗?另外,我不知道'rangefilt'的作用。当通过GUI发送图像路径时,将调用以下代码。
function [imC]=training(imPath)
im=imread(imPath);
x = 75;
y = 75;
reSim=imresize(im,[x,y]);
textureim=rangefilt(rgb2gray(reSim));
p=cat(3,reSim,textureim);
xi=[1:1:x]';
mi=repmat(xi, [1 y]);
yj=[1:1:y];
mj=repmat(yj,[x 1]);
mp=cat(3,mi,mj);
fp=cat(3,p,mp);
[pox poy poz]=size(fp);
pon=pox*poy;
vecim = reshape(fp,pon,poz);
[temp imC]=kmeans(double(vecim),5);
谢谢。
答案 0 :(得分:2)
function [imC]=training(imPath)
% //read in the image
im=imread(imPath);
% //Resize the image to be 75x75
x = 75;
y = 75;
reSim=imresize(im,[x,y]);
% // use rangefilt on a grayscale version
% //rangefilt returns (max-min) for each pixel of a 3x3 neighborhood
textureim=rangefilt(rgb2gray(reSim));
% //reshape them into two bands of p
p=cat(3,reSim,textureim);
% //These 4 lines are like meshgrid, create a vector, then repmat it into an image
xi=[1:1:x]'; % //'
mi=repmat(xi, [1 y]);
yj=[1:1:y];
mj=repmat(yj,[x 1]);
% // concatenate along third dimension (so we have another 2 band image)
mp=cat(3,mi,mj);
% //now we should have 4 bands, resim,textureim,mi,mj
fp=cat(3,p,mp);
% //get the size in x,y,z
[pox poy poz]=size(fp);
% //calculate the number of pixels in each band
pon=pox*poy;
% //reshape it to poz vectors of length pox*poy
vecim = reshape(fp,pon,poz);
% //run kmeans on the data which will cluster based on intensity, texture and position
[temp imC]=kmeans(double(vecim),5);