retain certain pixels in image



Thank you Image Analyst. Will try and post my results later.

"Image Analyst" <imageanalyst@xxxxxxxxxxxxxx> wrote in
message <fvss9o$bfu$1@xxxxxxxxxxxxxxxxxx>...
-----------------------------------------------
No, William - that won't work. What you need to do Philip
is to first find the objects in your image. There are
many ways to do this but basically you want to get your
color image down to a point where you can threshold it to
form a binary image. Then you do bwlabel() on it,
followed by regionprops(). The structure returned by
regionprops will have information (such as size, shape,
coordinates of pixels, etc.) in it for every object in
your image. You can then do whatever you want to do with
the information (e.g. make distributions or calculate
means). If you want to erase them from the image you can
find the indexes of the objects you want to erase and then
zero out the pixels from the labelled image. Then you
could threshold the labelled image at a value of 1 to form
a binary mask image, which you can then multiply by your
original image to zero out those parts of your image not
meeting your criteria (such as their area is more than 5
pixels or its shape is not rectangular, etc.) It might
sound more complicated than it really is. Once you have
the image ready for thresholding, the rest of it is only
like 8 or 9 lines of code.
Regards,
ImageAnalyst

Here's some expanded demo code for you that I wrote:

disp(' ');
disp('Running BlobsDemo.m...');
originalImage = imread('coins.png'); % Read in image
binaryImage = im2bw(originalImage, 0.4); % Threshold
to binary

subplot(3,2,1); imagesc(originalImage); colormap(gray
(256)); title('Original Image');
subplot(3,2,2); imagesc(binaryImage); colormap(gray(256));
title('Binary Image');

labeledImage = bwlabel(binaryImage, 8); % Label each
blob so can do calc on it
coloredLabels = label2rgb
(labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random
color labels

subplot(3,2,3); imagesc(labeledImage); title('Labeled
Image');
subplot(3,2,4); imagesc(coloredLabels); title('Pseudo
colored labels');

blobMeasurements = regionprops(labeledImage, 'all'); %
Get all the blob properties.
numberOfBlobs = size(blobMeasurements, 1);

% bwboundaries returns a cell array, where each cell
% contains the row/column coordinates for an object in the
image.
% Plot the borders of all the coins on the original
% grayscale image using the coordinates returned by
bwboundaries.
subplot(3,2,5); imagesc(originalImage); title('Outlines');
hold on;
boundaries = bwboundaries(binaryImage);
for k = 1 : numberOfBlobs
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary
(:,1), 'g', 'LineWidth', 2);
end
hold off;

fprintf(1,'Blob # Mean Intensity Area Perimeter
Centroid\n');
for k = 1 : numberOfBlobs % Loop through all
blobs.
% Find the mean of each blob. (R2008a has a
better way where you can pass the original image
% directly into regionprops. The way below works
for all versions including earlier versions.)
thisBlobsPixels = blobMeasurements(k).PixelIdxList; %
Get list of pixels in current blob.
meanGL = mean(originalImage
(thisBlobsPixels)); % Find mean intensity (in
original image!)
blobArea = blobMeasurements(k).Area; %
Get area.
blobPerimeter = blobMeasurements(k).Perimeter;
% Get perimeter.
blobCentroid = blobMeasurements(k).Centroid;
% Get perimeter.
fprintf(1,'#%d %18.1f %11.1f %8.1f %8.1f %8.1f\n', k,
meanGL, blobArea, blobPerimeter, blobCentroid);
end
msgbox('Finished running BlobsDemo.m. Check out the
figure window and the command window for the results.');


.



Relevant Pages

  • retain certain pixels in image
    ... zero out the pixels from the labelled image. ... originalImage = imread; % Read in image ... Get all the blob properties. ... fprintf(1,'Blob # Mean Intensity Area Perimeter ...
    (comp.soft-sys.matlab)
  • Re: outer perimeter binary blobs - vectorisation
    ... Your algorithm gets the enclosing perimeter - pixels that are outside ... the blob, ...
    (comp.soft-sys.matlab)
  • Re: Remove speckles in bilevel (bw) image
    ... Recall the definition of a black blob. ... the black pixels, ... connected component of B. They are also ... the top left corner of the black word b. ...
    (sci.image.processing)
  • Re: regionprops problem..
    ... % originalImage = imadjust; ... binaryImage = edge,'canny'); ... % Get all the blob properties. ... numberOfBlobs = size; ...
    (comp.soft-sys.matlab)
  • Re: Finding the largest blob in a binary image
    ... the points to get the minimum enclosing rectangle for each blob. ... I just need to find the largest blob, keep its pixels at '1'; and set all other pixels to '0', In other words, given an input binary image, I want to have as an output an image where the pixels of the largest blob are on and the rest are off. ... Then do a templated dilation of the binary holding the survivor pixels to regrow the large blobs back. ... Then use a fill algorithm using the distance map to reconstruct the original blobs using the survivor pixel locations as starting points. ...
    (sci.image.processing)