how to mark pixel as zero
2 ビュー (過去 30 日間)
古いコメントを表示
Hi all
I have a segmented image i want to process only the larger segment. so i want to make the remaining pixels as zero. Please help me how i can do it.
2 件のコメント
Image Analyst
2012 年 7 月 24 日
You don't need to make the remaining pixels zero in order to measure the largest "segment".
採用された回答
Image Analyst
2012 年 7 月 23 日
Use regionprops to get the areas then get them all in an array so you can determine the largest.
measurements = regionprops(labeledImage, 'Area');
allAreas = [measurements.Area];
[sortedAreas sortIndexes] = sort(allAreas);
% Then mask your image or create a new one from the largest blob.
3 件のコメント
Image Analyst
2012 年 7 月 24 日
編集済み: Image Analyst
2012 年 7 月 24 日
You can get the largest region. It's sortIndexes(1). Just extract the label for the largest image with ismember(). Then turn it into a binary image and use that to "mark all pixels as zero except largest region" in your original image.
biggestLabel = ismember(labeledImage, sortIndexes(1));
binaryImage = biggestLabel > 0;
% If you want the original image masked:
maskedImage = grayImage;
maskedImage(~binaryImage) = 0;
If this code doesn't work for you, let me know tomorrow and maybe I can adapt my blobs demo (in my File Exchange) to find the largest blob. But like I said in the comment, you don't need to zero anything out to get the measurements of the largest blob, so I don't know why you think you do, unless you just want to display it for curiosity's sake.
Image Analyst
2012 年 7 月 24 日
Muhammad, you can color your labels like this, instead of all that code you gave in your comment below:
labeledImage = bwlabel(binaryImage, 8); % Label each blob so we can make measurements of it
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
imshow(coloredLabels);
その他の回答 (1 件)
jagadeeshwar
2012 年 7 月 23 日
hai imran just crop the image which segment u want it can be enlarge after crop operation
4 件のコメント
参考
カテゴリ
Help Center および File Exchange で Image Data Workflows についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!