threshold multiple values at the same time
显示 更早的评论
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 ?
采纳的回答
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?
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)
