필터 지우기
필터 지우기

Echocardiogram and image processing

조회 수: 10 (최근 30일)
Zo
Zo 2019년 2월 12일
편집: Agnish Dutta 2019년 2월 25일
How do i measure the width and the area of the red portion of the image attached?

채택된 답변

Agnish Dutta
Agnish Dutta 2019년 2월 25일
편집: Agnish Dutta 2019년 2월 25일
First load the image into the workspace by dragging and dropping the .PNG file into the MATLAB window. A new window will open up allowing you to set the various options for loading. By default the image will be loaded as a matrix of uint8 values.
The given problem can be sorted out by thresholding the different channels of the image file. Colored image files in MATLAB generally exist as 3D matrices, with each layer containing intensity values of one of Red, Blue and Green. You can therefore select threshold values in the range 0 - 255 to adjust the sensitivity of your filter to the various colors. Set a high threshold for red and low ones for green and blue. Then create a mask containing 0 or 1 values based on whether the intensity values in the different channels are in the correct range.
mask = uint8(inputImg(:, :, 1) >= th1 & inputImg(:, :, 2) <= th2 & inputImg(:, :, 3) <= th3);
By changing the values of th1, th2 and th3 you can adjust the sensitivity of the filter to red, blue and green.
The generated mask will contain 0 or 1 corresponding to regions with high value of intensity for red and low values for green and blue. You can then count the number of 1's in the mask and divide it by the total number of pixels in the image to obtain the area of the target region as a percentage of the total area of the image.
The following is a function for doing this:
function percent = Threshold(inputImg, th1, th2, th3)
mask = uint8(inputImg(:, :, 1) >= th1 & inputImg(:, :, 2) <= th2 & inputImg(:, :, 3) <= th3);
outputImg = inputImg;
outputImg(:, :, 1) = outputImg(:, :, 1) .* mask;
outputImg(:, :, 2) = outputImg(:, :, 2) .* mask;
outputImg(:, :, 3) = outputImg(:, :, 3) .* mask;
imshow(outputImg);
white = sum(sum(mask));
total = size(mask, 1) * size(mask, 2);
percent = white / total;
end
Once you have the percentage, simply multiply it with the actual total area of the original image.
PS: I've seen that th1 = 70, th2 = 70 and th3 = 70 work for the given image.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by