This is my code that i used
clc;
clear all;
clear;
img1 = imread ('Picture1.png');
%subplot(1,3,1)
%imshow(img1);
% Convert RGB image to chosen color space
I = rgb2hsv(img1);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.889;
channel1Max = 0.001;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.000;
channel2Max = 1.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.000;
channel3Max = 1.000;
% Create mask based on chosen histogram thresholds
sliderBW = ( (I(:,:,1) >= channel1Min) | (I(:,:,1) <= channel1Max) ) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
%subplot(1,3,2)
%imshow(sliderBW)
diskElem = strel('sphere',3);
IBWopen=imopen(sliderBW, diskElem);
%subplot(1,3,3);
%imshow(IBWopen )
%%
hbobanalysis= vision.BlobAnalysis('MinimumBlobArea',200,...
'MaximumBlobArea',3000);
[objArea, objCentrroid, bboxout] = step(hbobanalysis,IBWopen);
bboxout
%%
Ishape=insertShape(img1, "rectangle",bboxout,'LineWidth',4);
figure
subplot(1,2,1);
imshow(Ishape )
%%
%%
release(hbobanalysis)