How to remove an apple twig from binary image?

조회 수: 1 (최근 30일)
K Vermeulen
K Vermeulen 2020년 10월 21일
답변: yanqi liu 2022년 1월 5일
Good day,
I want to determine the diameter of an apple. The only problem is we don't know how to exclude the twig of the apple.

답변 (2개)

Nitin Kapgate
Nitin Kapgate 2020년 10월 27일
You can use the following code snippet to remove the area of twig from the image of apple:
% Read the input binary image
I = imread("Apple_Binary.png");
imshow(I);
% Converting the binary image to 8-bit unsigned integers
I = im2uint8(I);
% Interactively draw a polygon and select the area of apple twig as ROI
roi = drawpolygon(gca,"Color","yellow");
% Create a mask out of ROI
mask = createMask(roi, I);
% Display the Mask
imshow(mask);
% Fill the regions in the input image using the mask image
J = regionfill(I,mask); % J is the output image, with twig removed
imshow(J);

yanqi liu
yanqi liu 2022년 1월 5일
clc; clear all; close all;
bw = imread("https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/387348/Apple_Binary.png");
figure; imshow(bw);
bw2 = imopen(bw, strel('disk', 20));
bw(~bw2) = 0;
figure; imshow(bw);

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by