Using 2 nested for loops: Evaluate each pixel's R,G,B value : If the pixel's R value is greater than the user's threshold value for Red, set that value = to threshold instead
5 次查看(过去 30 天)
显示 更早的评论
The underlined part is what I need help with. I have the threshold values and the image part down, I am just not sure how to do this for loop.
Using 2 nested for loops:
a. Evaluate each pixel's R,G,B value
b. If the pixel's R value is greater than the user's threshold value for Red, set that value equal to the threshold instead
c. If the pixel's R value is less than or equal to the threshold value for Red, leave it alone (nothing changes)
d. Do this for each pixel's Green and Blue intensity values
For reference, this is the first part of the question that I already have done. I just need the loop part.
a) Bring in the data associated with the image "zippy.jpg" available on Brightspace.
b) Prompt the user to enter 3 values:
a. A threshold value for the red channel (must be an integer value between 0-255)
b. A threshold value for the green channel (must be an integer value between 0-255)
c. A threshold value for the blue channel (must be an integer value between 0-255)
Any help is appreciated, I still struggle to understand loops.
Thank you very much!
J
0 个评论
采纳的回答
DGM
2022-4-19
In practice you wouldn't use a loop at all.
A = imread('peppers.png');
maxthresh = uint8([100 150 200]); % [R G B]
B = min(A,permute(maxthresh,[1 3 2]));
imshow(B)
Though if you want to do it in a loop, you can. It'll just be unnecessarily slow.
A = imread('peppers.png');
maxthresh = [100 150 200]; % [R G B]
maxthresh = uint8(permute(maxthresh,[1 3 2]));
[h,w,~] = size(A);
for r = 1:h
for c = 1:w
A(r,c,:) = min(A(r,c,:),maxthresh);
end
end
imshow(A)
6 个评论
DGM
2022-4-20
Think of this line
% function f() is a function of the input argument x
% and its output is log(x)
f = @(x) log(x);
as basically any regular old MATLAB function
function fx = myfunction(x) % define output and input arguments and function name
fx = log(x); % assign a value to the output arg based on the input arg
end
The x that's used in either case is local to the function itself. You could write
f = @(a) log(a);
and it would mean the same thing, so don't confuse the x on that line with the symbolic variable x that's used on prior lines.
Either way, you're just creating a function that accepts numeric inputs and produces numeric outputs. When you call quad(), it will internally call f() in order to evaluate the function and approximate its integral.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
