classifying images based on their object measurement properties and labeling them as such, how can I do this?
조회 수: 1 (최근 30일)
이전 댓글 표시
The following code is able to measure properties of the images read in using regionprops and save them to a features.mat file:
regionprops...
% Calculate features for this zone
numObjects = cc.NumObjects;
if numObjects > 0
areas = [statscc.Area];
profileCounts(k) = numObjects;
totalArea(k) = sum(areas)
zoneArea(k) = areaOfEachZone(k);
avgSize(k) = mean(areas)
circularities = [validObjects];
avgCircularity(k) = mean(circularities(isfinite(circularities)));
ferets = [statscc.MajorAxisLength];
avgFeret(k) = mean(ferets)
minFerets = [statscc.MinorAxisLength];
avgMinFeret(k) = mean(minFerets)
end
%===============================================================================
% save features to a structure
features(m).filename = allFileNames{m};
features(m).totalArea = totalArea;
features(m).avgSize = avgSize;
features(m).zoneArea = zoneArea;
features(m).AvgCircularityy = avgCircularity;
features(m).AvgFeret = avgFeret;
features(m).AvgMinFeret = avgMinFeret;
features(m).profileCounts = profileCounts;
however, I want to train this code to discern between images with similar or different features and be able to display "this is a control iamge this is a non control image etc." How can i do this? I have no idea how to approach this. But i have tried other ways and can't reach a conclusion. Can you please help? Thanks!
댓글 수: 0
채택된 답변
Image Analyst
2023년 3월 28일
It's a generic, general purpose demo of how to threshold an image to find blobs, and then measure things about the blobs, and extract certain blobs based on their areas or diameters. For example I show you how to extract different denomination coins based on their diameter.
댓글 수: 2
Image Analyst
2023년 3월 28일
If you'll just try the demo and look at the source code you'll see how to do it. Here is the code. You'll see in this well commented code how I got an image of just the dimes:
%------------------------------------------------------------------------------------------------------------------------------------------------------
% Now I'll demonstrate how to select certain blobs based using the ismember() function and extract them into new subimages.
% Let's say that we wanted to find only those blobs
% with an intensity between 150 and 220 and an area less than 2000 pixels.
% This would give us the three brightest dimes (the smaller coin type).
allBlobIntensities = [props.MeanIntensity];
allBlobAreas = [props.Area];
subplot(3, 3, 7);
histogram(allBlobAreas);
% Get a list of the blobs that meet our criteria and we need to keep.
% These will be logical indices - lists of true or false depending on whether the feature meets the criteria or not.
% for example [1, 0, 0, 1, 1, 0, 1, .....]. Elements 1, 4, 5, 7, ... are true, others are false.
allowableIntensityIndexes = (allBlobIntensities > 150) & (allBlobIntensities < 220);
allowableAreaIndexes = allBlobAreas < 2000; % Take the small objects.
% Now let's get actual indexes, rather than logical indexes, of the features that meet the criteria.
% for example [1, 4, 5, 7, .....] to continue using the example from above.
keeperIndexes = find(allowableIntensityIndexes & allowableAreaIndexes);
% Extract only those blobs that meet our criteria, and
% eliminate those blobs that don't meet our criteria.
% Note how we use ismember() to do this. Result will be an image - the same as labeledImage but with only the blobs listed in keeperIndexes in it.
keeperBlobsImage = ismember(labeledImage, keeperIndexes);
% Re-label with only the keeper blobs kept.
labeledDimeImage = bwlabel(keeperBlobsImage, 8); % Label each blob so we can make measurements of it
% Now we're done. We have a labeled image of blobs that meet our specified criteria.
subplot(3, 3, 7);
imshow(labeledDimeImage, []);
axis image;
title('"Keeper" blobs (3 brightest dimes in a re-labeled image)', 'FontSize', captionFontSize);
elapsedTime = toc;
fprintf('Blob detection and measurement took %.3f seconds.\n', elapsedTime)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!