matlabimage-processingdiplib

DIPimage measure missing argument


enter image description hereI am trying to use DIPimage to get some measurements of each object in an image and I get this error:

Error using dip_measure
DIPlib Error in function dip_Measure.
DIPlib Error in function dip_ImageCheck: Data type not supported


Error in measure (line 209)
data = dip_measure(object_in,gray_in,measurementID,objectIDs,connectivity);

Error in Untitled (line 13)
msr = measure(b, [], ({'size', 'perimeter','podczeckShapes'}))

How can I solve it?

Code:

Image = rgb2gray(imread('pillsetc.png'));

BW = imbinarize(Image);
BW = imfill(BW,'holes');
imshow(BW);

[B,L] = bwboundaries(BW,'noholes');
k = 1;
b = B{k};
y  = b(:,2);
x  = b(:,1);

msr(k) = measure(BW, [], ({'size', 'perimeter','podczeckShapes'}))
sz = msr.size;
podczeckShapes = podczeckShapes;

Solution

  • One problem with your code is the call to imfill. Because the image has bright values all around the image, it is considered that there's a large object with a hole, and your actual objects are inside this hole. imfill fills the hole, leaving the whole image white.

    Instead, I suggest the following code to remove the frame:

    Image = rgb2gray(imread('https://i.sstatic.net/fmqAF.jpg'));
    BW = imbinarize(Image);
    
    BW = BW - bpropagation(false(size(BW)), BW);
    

    Because we used a filter in DIPimage, the BW variable now contains a dip_image object, not a normal MATLAB array. dip_array(BW) extracts the normal MATLAB array that is inside. The dip_image object behaves differently from a MATLAB array. For example, you can display it to an interactive figure window by just typing its name:

    BW
    

    Next, we apply labeling so that we know which object ID in the measurement data corresponds to which object:

    lab = label(BW);
    dipshow(lab,'labels')
    

    Now we can apply the measurement function. If we use BW as input, label will be called on it. Since we already have that result, let's use it directly:

    msr = measure(lab, [], {'size', 'perimeter','podczeckShapes'});
    

    Let's examine results for object ID 8, which is the large square:

    sz = msr(8).size
    square = msr(8).podczeckShapes(1)
    triangle = msr(8).podczeckShapes(3)
    

    There are other things you can do with the measurement structure, I suggest you read the documentation. For example, we can remove from it the measurement for the littlest objects, which to me look like noise:

    msr = msr(msr.size>100); % remove measurement for noise