Attempting to alter the color of connected components in a label matrix that are under a threshold pixel area.

2 visualizaciones (últimos 30 días)
Hello,
I am attempting to take this image and color the circles that are smaller than 1200 pixels cyan:
Here's what I've done so far.
%Assuming image already read in as I
[L, num] = bwlabel(I); %return label matrix and num of connected components of I
S = regionprops(I)
p = [S.Area] %create vector consisting of areas of each connected component in I
for i=1:num
if(p(i) < 1200) %finding Areas in the vector that are less than threshold value
%not sure how to proceed from here
end
end
Any guidance would be appreciated.

Respuestas (2)

Harsha Phadke
Harsha Phadke el 13 de Abr. de 2017
What I would suggest doing here is, using the binary image as a mask. Binary image has logical values, thus to insert any color to the pixels you would require a uint8 image from what I understand. If you multiply the actual image with the mask image, you will be able to generate a uint image and then just fill the values for the pixels with the required color. You can even look at the following link which might be helpful. https://www.mathworks.com/matlabcentral/answers/153533-change-color-in-black-and-white-rgb-image

Image Analyst
Image Analyst el 14 de Abr. de 2017
Try this:
filename = 'Fig1126(a) - Copy.jpg';
grayImage = imread(filename);
grayImage = grayImage(:, :, 1); % Extract red into a 2D array.
binaryImage = grayImage > 128;
subplot(2, 2, 1);
imshow(binaryImage);
title('Original image', 'FontSize', 25);
% Extract blobs smaller than 2000 pixels.
smallBlobs = bwareafilt(binaryImage, [1, 1200]);
subplot(2, 2, 2);
imshow(smallBlobs);
title('Small Blobs', 'FontSize', 25);
% Make indexed image
indexedImage = double(binaryImage) + double(smallBlobs);
% Now small blobs have the value 2 instead of 1
h3 = subplot(2, 2, 3);
imshow(indexedImage);
% Make colormap
cmap = [0,0,0;1,0,0;0,1,1];
colormap(h3, cmap);
caxis([0,2]);
colorbar;
title('Pseudocolored', 'FontSize', 25);
Now, your circles are touching to form bigger blobs and I didn't bother to separate them. If you want to do that, you can see http://blogs.mathworks.com/steve/2013/11/19/watershed-transform-question-from-tech-support/ for directions on how to use watershed transform to split them apart.

Categorías

Más información sobre Images en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by