matlab编程中遇到问题,但是不知道错在哪里,求高手指教,3Q~

2024-11-27 22:15:08
推荐回答(1个)
回答1:

(gca,'ydir','reverse');
这句是什么意思啊?

继续。搞明白了。程序没有问题,通了,关键是执行到grain = imcrop(labeled) 时,要在第六个个图中(黑白图)左击鼠标,之后就通了,呵呵。

%程序代码:test2.m
clear, close all,I = imread('rice.tif');
imshow(I)
background = imopen(I,strel('disk',15));
figure,imshow(background)
figure, surf(double(background(1:8:end,1:8:end))),zlim([0 255]);
%(gca,'ydir','reverse');
I2 = imsubtract(I,background); figure, imshow(I2);
I3 = imadjust(I2, stretchlim(I2),[0 1]);figure, imshow(I3);
level = graythresh(I3);bw = im2bw(I3,level); figure, imshow(bw)
[labeled,numObjects] = bwlabel(bw,4);

grain = imcrop(labeled) %就是它!!!

RGB_label = label2rgb(labeled, @spring,'c','shuffle');
figure,imshow(RGB_label);
graindata = regionprops(labeled,'basic')
graindata(51).Area, graindata(51).BoundingBox, graindata(51).Centroid
allgrains=[graindata.Area]
max(allgrains)
biggrain = find(allgrains==ans)
mean(allgrains)
figure %加了一个图,否则覆盖了上一个了。
hist(allgrains,20)