how to compute min for image with black border?

Hi, I have an image with black border in 2000 * 2000.after using min function the output is 0 or 1.that The minimum is related to border of the image that is black.how to compute min or max other than black border? my code is here.by this code output min is NaN.
img=imread('image.tif');
figure(1),imshow(img),title('original');
[M,N]=size(img);
for i=1:M
for j=1:N
if img(i,j)<1
img(i,j)=NaN;
end
end
end
minofimg=min(min(img));

 채택된 답변

Chad Greene
Chad Greene 2016년 6월 8일

1 개 추천

What about
min(img(img~=0))
That is, the minimum value of img values that are not zero.

댓글 수: 6

ok.thanks.Is it possible to access pixels Apart from zero intensity by using binary mask ?
%msk is binary mask
image=img(img~=msk);
Yep, looks good to me.
Looks bad to me.
For one thing, "image" is a reserved built-in function and you never want to use that for a variable name. Secondly, if the min intensity value of your image, not including the black surrounding border, is zero, the above code will not tell you that it's zero. You'd get the next darkest value, which is wrong. Better (more robust) is to find the border and crop it off and then use min().
Ah, very good points!
fred bnm
fred bnm 2016년 6월 17일
how to find the border and crop it off?
You can specify the range of rows and columns you want to keep. For example start with this image:
img = imread('cameraman.tif');
image(img)
colormap(gray)
And clip the first 49 rows, and the last 47 rows. Also clip the first 124 columns:
keeprows = 50:209;
keepcols = 125:256;
img_trimmed = img(keeprows,keepcols);
image(img_trimmed)

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

질문:

2016년 6월 8일

댓글:

2016년 6월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by