Hello, can anyone help me how to find the only whitepixels that mushrooms occupied in given image??

2 views (last 30 days)
B Anuradha
B Anuradha on 27 Sep 2021
Commented: B Anuradha on 1 Oct 2021
My Code:
clc;
clear all;
close all;
I=imread('50pic1.jpeg');
figure;
imshow(I)
g = rgb2gray(I);
figure;
imshow(g)
impixelinfo
BW=imbinarize(g);
figure;
imshow(BW)
noofWhitepixels=sum(BW(:))
disp(noofWhitepixels)
By using this code i am getting All no of whitepixels in an image but i only want whitepixels of mushrooms that occupied in an image

Accepted Answer

Pratyush Roy
Pratyush Roy on 30 Sep 2021
Hi Anuradha,
As per my understanding you want to find onl the white pixels in the image of the mushroom.
As a workaround, you can try using the imerode function to remove small white patches after binarizing the image with imbinarize. The following code snippet demonstrates the use of bith these functions:
im1 = imread('mushroom.jpeg');
gray_image = rgb2gray(im1);
bw_image = imbinarize(gray_image);
se = strel('line',11,90);
erodedBW = imerode(bw_image,se);
imshow(erodedBW)
Hope this helps!

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by