threshold multiple values at the same time
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hi am I trying to find the value of a global threshold (mean, median, 50, 100, 150, 200)
Can someone assist me asap please?
TIA!
댓글 수: 3
Please explain your question more.
I am trying to do a global threshold for the given values 50, 100, 150, 200
all at once and have matlab project all images respectfully!!
I do not know how to start the syntax hence the reason for me asking!!!
Help if you can please!!!
What does it mean to do a global threshold for the given values 50, 100, 150, 200 ?
채택된 답변
Walter Roberson
2019년 8월 6일
nd = ndims(YourImageArray);
Thresholded_arrays = bsxfun(@le, YourImageArray, reshape([50, 100, 150, 200], [ones(1,nd), 4]) );
Now Thresholded_arrays is one higher dimension than your original array. For example if your original array was 512 x 768 x 3 x 128 (that is, a stack of 128 RGB images each of which is 512 x 768 pixels), then Thresholded_arrays would be 512 x 768 x 3 x 128 x 4, and Thresholded_arrays(:,:,:,:,1) would be YourImageArray thresholded at value 50.
댓글 수: 15
I am a beginner and this is frustrating What about a simple code like I=imread(image) B=[50,100,150,200] Threshold =image>B
I am not sure what to do to get the images Print as titled 50,100,150,200
Please assist! I don't get your answer
B = [50,100,150,200];
nB = length(B);
I = imread(image);
thresholded_I_binary = bsxfun(@le, I, reshape(B, [1 1 1 nB]));
thresholded_I_image = im2uint8(thresholded_I_binary);
for K = 1 : nB
subplot(1, nB, K);
imshow(thresholded_I_image(:,:,:,K));
title(sprintf('threshold = %f', B(K)));
end
Note that you will get colored outputs if the original image is RGB.
Your problem would be easier if you were to state what kind of image (grayscale, pseudocolor, RGB, RGBA, CMYK, grayscale+A) that you are reading in, and if you were to state more clearly what result you expect to display, especially if the input is not grayscale. You would probably also be less frustrated with trying to understand the code if you were to relax the requirement that all of the threshold have to be calculated "at the same time": this is something that would be clearer written as a loop instead of calculating everything "at the same time".
Hi walter, my apologies,
I am working with a grayscale image! Would it be to much to ask you to comment on each line so that i can learn what it does
Hi Walter the code did not work I tried it! can it be a little easy?
B = [50,100,150,200];
nB = length(B);
for K = 1 : nB
subplot(1, nB, K);
imshow(I <= B(K));
title(sprintf('threshold = %f', B(K)));
end
ok let me try now thanks in advance
Hi Walter,
This my code I am trying to get that threshold running inside of here
i=imread('car.jpg');
gr=rgb2gray(i);
figure,imshow(gr), title("Origina image");
[count,bins]=imhist(gr);
count(100);
imhist(gr);
C=[150,100,20,90,75];
T = [50,100,150,200];
for cadd=1:length(C)
newim=adcon(gr,C(cadd));
% subplot(2,3,c),imshow(RImage), title(sprintf("%c constant",c));
subplot(2,3,cadd),imshow(newim),title(sprintf("%C Constant",C));
drawnow;
end
function newim = adcon(gr, Constant)
[r, c]=size(gr);
newim=gr;
for i=1:r
for j=1:c
newim(i,j)=gr(i,j)+Constant;
if newim(i,j)>255
newim(i,j)=255;
else if newim(i,j)<0
newim(i,J)=0;
end
end
end
end
end
Your input, gr, is uint8. When you add a constant to uint8, it is not possible for the resulting value to be > 255 and it is not possible for the resulting value to be < 0
>> uint8(7)+(-10)
ans =
uint8
0
>> uint8(250)+10
ans =
uint8
255
Hi Walter, a huge thank you for responding ! But how do i understand what your're saying clearer! I don't get it! Can you break it down further for a beginner so that i never forget please?
Walter Roberson
2019년 8월 7일
편집: Walter Roberson
2019년 8월 7일
Replace your existing adcon function with:
function newim = adcon(gr, Constant)
newim = gr + Constant;
Replace
subplot(2,3,cadd),imshow(newim),title(sprintf("%C Constant",C));
with
subplot(2,3,cadd),imshow(newim),title(sprintf("%C Constant",C(cadd)));
Ok i will try it! But there are no comments to understand what you mentioned about the 8bit grayscale image I would like to get that understand as well please! Thanks in advance Walter I appreciate it loads!!
Hi Walter this made no difference to me!! can you tell what i should be looking for in reference to the changes that should take place?
The images presented themselves as they were before!!!
Is this in reference to the 8bit features which you highlighted some comments ago?
Thanks for guiding me you have done a great job thus far!!
Hi Walter,
I tried and tried it did work Walter i am so greatful!!!! yippy!!!
all the lables are now on the image I have been trying to get that to work for the longest while and now realise the alterations.
Ah the next thing is I am trying to work out adpative, global/local thresholding with the same constant!! can you help me please?
and thanks for all your assistance if you didn't help me I would not have gotten this far!!!
I am so happy walter just to figure it out!!
Adaptive thresholding and local thresholding do not use constants. The code I showed is already for global thresholding.
"If you convert a number that is larger than the maximum value of an integer data type to that type, MATLAB sets it to the maximum value. Similarly, if you convert a number that is smaller than the minimum value of the integer data type, MATLAB sets it to the minimum value."
The calculation A+B in uint8 is like
uint8( max(min(double(A)+double(B),255), 0) )
There is no need to go through and test whether A+B is in the range 0 to 255, because that kind of limit is already built-in to the way that uint8() is defined to operate.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Calculus에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
