MATLAB: How to find the least pixel intensity value for each connected component

digital image processingimage processingImage Processing Toolbox

Binary image:
finalcandidates.png
Green image:
Ig.jpg
I have a binary image with some pixels as 1 and some as 0 forming a image of group of connected components(white spots within the black image).I need to find the intensities of the pixels of these white spots in other image(green image) and find the pixel with lowest intensity and its value in the green image.I need to find the lowest intensity pixel and its value in the green image for all the white clusters in the binary image.
Can somebody please help me how to find it?
Thank you.
I am enclosing the binary image as finalcandidates,png and the green image as Ig.png.

Best Answer

See demo below. Adapt as needed:
grayImage = imread('coins.png');
subplot(2, 2, 1);
imshow(grayImage);
subplot(2, 2, 2);
histogram(grayImage)
binaryImage = imfill(grayImage > 90, 'holes');
binaryImage = bwareafilt(binaryImage, 10);
subplot(2, 2, 3);
imshow(binaryImage);
subplot(2, 2, 4);
[labeledImage, numBlobs] = bwlabel(binaryImage);
props = regionprops(labeledImage, grayImage, 'PixelValues', 'PixelList')
for k = 1 : numBlobs
% Fin the min value of this blob's pixel values.
thisBlobsMin = min(props(k).PixelValues);
% Get locations in this blob
mask = ismember(labeledImage, k);
maskedImage = grayImage .* uint8(mask);
% Find all the rows and columns where it appears
[rows, columns] = find(maskedImage == thisBlobsMin);
imshow(maskedImage);
axis('on', 'image');
hold on;
plot(columns, rows, 'r+', 'LineWidth', 2, 'MarkerSize', 15);
hold off
caption = sprintf('Showing cross at %d mins for blob #%d of %d.\n', ...
length(rows), k, numBlobs);
title(caption, 'FontSize', 12);
fprintf('%s\n', caption);
end
fprintf('Done!\n');