MATLAB: Hi, I need to get the X,Y coordinates of white pixels area. can anyone help me to do this,please

and y coordinates of the rectangle(white pixel)i need to get the x

this is the code I used.
I1 = imread('try.jpg'); % read image
ID1 = im2double(I1); % convert to double
IDG1 = rgb2gray(ID1); % conver to gray scale
t = 112; % set a thresholding value
IT = im2bw(IDG1, t/255); % apply the threshold
I2 = ~IT; % get a nigative image
I3 = bwareaopen(I2,40); % get rid of small unwanted pixels
I4 = imclearborder(I3); % clear pixels of the borders
I5 = bwareaopen(I4,60); % get rid of small unwanted pixels

I6 = imfill(I5,'holes'); % fill the gap on the ball top part
I7 = imclearborder(I6); % get rid of small unwanted pixels
imshow(I7)

Best Answer

Use regionprops to get the size and location of each white region, and keep only the largest.
regionstats = regionprops(I7, 'all');
[~, largestidx] = max([regionstats.Area]); %find index of largest region
regionstats(largestidx).BoundingBox %coordinate of bounding box of largest region
regionstats(largestidx).PixelList %coordinate of all pixels in the region as a matrix