필터 지우기
필터 지우기

Using regionprops to change intensity of blobs

조회 수: 2 (최근 30일)
RIshabh Golchha
RIshabh Golchha 2017년 9월 11일
답변: Image Analyst 2017년 9월 11일
I am having a gray scale image which has certain blobs. The region apart from these blobs has intensity of 0. Using regionprops() I can extract various properties like Area, mean intensity of each blob.
Based on these mean intensity of a blob I want to modify the intensity of that blob. Any ideas on how I can achieve that?

채택된 답변

Matt J
Matt J 2017년 9월 11일
편집: Matt J 2017년 9월 11일
Using regionprops you can also extract the PixelIdxList of the different blobs. You can use that to modify the pixels in the desired region,
S=regionprops(...,'PixelIdxList');
myImage(S(i).PixelIdxList)= new_Intensities;
  댓글 수: 1
Steve Eddins
Steve Eddins 2017년 9월 11일
For an example that illustrates Matt's answer, see my 21-Aug-2007 blog post. Look for the code following "Here's a loop that replaces the pixel values for each coin by the mean pixel value for that coin."

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2017년 9월 11일
You're going to need to get the MeanIntensity of course, and the PixelIdxList. So...
[labeledImage, numBlobs] = bwlabel(binaryImage);
props = regionprops(labeledImage, grayImage, 'MeanIntensity', 'PixelIdxList');
% Replace each blob with some other intensity based on the blob's mean intensity
for k = 1 : numBlobs
thesePixelIndexes = props(k).PixelIdxList;
thisMeanIntensity = props(k).MeanIntensity;
if thisMeanIntensity < 100
% If mean intensity is less than 100,
% replace all pixels in the blob in the original gray scale image with a value of 1.
grayImage(thesePixelIndexes) = 1;
elseif thisMeanIntensity < 200
% If mean intensity is less than 200,
% replace all pixels in the blob with a value of 2.
grayImage(thesePixelIndexes) = 2;
else % thisMeanIntensity <= 255
% If mean intensity is more than 200,
% replace all pixels in the blob with a value of 3.
grayImage(thesePixelIndexes) = 3;
end
end
Change the numbers and add "if" blocks if you have more and/or different ranges for your mean intensities and desired replacement gray levels.
If you want, you can replace the values in the binary image, the labeled image, or create an entirely new image altogether.

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by