필터 지우기
필터 지우기

Threshold image after applying mask

조회 수: 13 (최근 30일)
Ihiertje
Ihiertje 2017년 5월 1일
댓글: Image Analyst 2020년 3월 30일
Hi,
I have an image (object + background, uint16) and I remove the background of this image by using imbinarize. So the background has a value of zero and the object has its original values (1000 - 7000). Now I want to apply a threshold only on the object. I tried to change the zero values to nan, but that did not work. How can I only threshold the object, without all the zeros of the background?
Thanks!
Edit: I attached a photo of my file. Inside the red line is the object and outside is the background (black). I want to apply a threshold on the intensity of the object. I tried to remove the background by a mask, but when applying an automatic threshold, the background is still included. So hope someone can help.

채택된 답변

Image Analyst
Image Analyst 2017년 5월 1일
I think imbinarize() and graythresh() work on 1-D images. So if you want to determine the a threshold only considering the gray levels of the gray ring and not considering the black background, extract the ring pixels into a list and pass them to graythresh():
ringPixels = originalImage(originalImage > theThreshold); % No black pixels here
newThreshold = graythresh(ringPixels);
Since you've already masked the image by doing something like
maskedImage = originalImage; % Initialize
maskedImage(mask) = 0; % Erase background.
you could also do the first line like this
ringPixels = maskedImage(maskedImage > 0);
and then call graythresh();
  댓글 수: 3
Dua Arshad
Dua Arshad 2020년 3월 30일
Sir, How can i apply this graythresh masking concept on the whole grayscale image. i have to segment the backgroud of fruits.
is it possible if i take first the binary image and make the background black and then use its mask to the gray image to remove background?
Image Analyst
Image Analyst 2020년 3월 30일
You can do :
% Assume background is dark. Threshold to find dark pixels.
backgroundMask = grayImage < 50; % or > or whatever value works for you instead of 50.
% Blacken background.
grayImage(backgroundMask) = 0; % Set background to 0.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by