Thresholding based on smaller domains
이전 댓글 표시
Hello all
I have an image (intl16) that I'm trying to detect defcts on them. First, what I tried to do was to get the mean/median value of the whole image and define some if condition to set any i,j to1 if they are above or lower the threshold (upper and lower). However, I have some images whic have regins with either higher or lower grayscle value. I wanted to try to have some small doimns (like 10by10 for the image 5120by5120) and get the mean value for the domins and theresholding for each domin separately. Is there anyone who has some experince to let me know how I can approach this problem?
any help will be really apprecited. I cannot share the imges, sorry.
답변 (3개)
KALYAN ACHARJYA
2021년 2월 13일
편집: KALYAN ACHARJYA
2021년 2월 13일
You can try with any size, lets suppose you have image named as 'grayImage' (256x256)
grayImage=randi([0,255],[256,256]); %Random Image Data
% Find Mean
meanImage=mean2(grayImage)
% or Find Median
medImage=median(grayImage(:))
Define threshold, say "th"
th=150;
% Next suppose assign all those pixels greater than mean value of the image equal to zero (Black)
grayImage(grayImage>meanImage)=0;
Deals with threshold
grayImage(grayImage>th)=0;
More ways.......
Or Any logical condition as you wish to apply on image based on mean or median of the image.
Good Luck!
:)
Kalyan
댓글 수: 2
Sasan Shadpour
2021년 2월 14일
KALYAN ACHARJYA
2021년 2월 14일
I have shared the steps described in the description of the question. It would be easy to answer by looking at the images.
Jan
2021년 2월 14일
Two solution:
X = randi([0,10], 12, 12); % arbitrary test data
n = 10; % Neighborhood
Y = conv2(x, ones(n, n) / (n * n), 'same');
mask = (X - Y) > Thresh;
X(mask) = Y(mask);
Or calculate the moving mean by:
Y1 = movmean(X, 10, 1);
Y = movmean(Y1, 10, 2);
% Replacing see above
This differs for the elements on the borders.
See also: medfilt2
댓글 수: 6
Sasan Shadpour
2021년 2월 15일
Jan
2021년 2월 15일
Start at:
help conv2
doc conv2
The convolution multiplies a window taken from the larger input with the matrix and calculates the sum over the elements. For ones(n,n)/(n*n) this is the average over [n x n] submatrices.
Image Analyst
2021년 2월 15일
The code blurs your image. If the gray levels vary as you move around the image, a global threshold will not work. You need to either flatten your image or get a custom threshold for each pixel in the image.
Sasan Shadpour
2021년 2월 16일
Image Analyst
2021년 2월 16일
Did you even try the imbinarize() with the adaptive option like I suggested below?
Sasan Shadpour
2021년 2월 16일
편집: Sasan Shadpour
2021년 2월 16일
Image Analyst
2021년 2월 14일
0 개 추천
imbinarize() has an 'adaptive' option try that. Otherwise try to use adapthisteq() to flatten the image so that you can use a global threshold. Attach a similar image (non-secret, non-proprietary) if you need more help.
카테고리
도움말 센터 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

