|
From: Image Analyst on 7 May 2008 14:27 "William Thielicke" <w.thielicke.doesntLikeSpam.(a)rug.nl> wrote in message <fvsnv0$k78$1(a)fred.mathworks.com>... > Hey! > I am also new, but can't you use A=imread('...') and then > B=A(1:5 1) > > Oder something like that (in a correct syntax.... ;-D) > Cheers, > William ----------------------------------------------------------- ----------------------------------------------- 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.');
|
Pages: 1 Prev: running a Windows program from MATLAB Next: problem on compiling exe containing dll file |