Multible Pixel Values Doesn't Allow Bigger Than 255
Mostra commenti meno recenti
Hey there,
I want to make a project about image processing and i have a problem.I want to multiple pixel images and matlab result is not be bigger than 255.
Here is formula :

Here is my code(k is constant,Yout and yinv is my images)
for index1= 1 : m
for index2 = 1 : n
Ymix(index1,index2) = Yout(index1,index2)*yinv(index1,index2)*k;
end
end
Risposta accettata
Più risposte (2)
Steven Lord
il 18 Mar 2017
0 voti
One or more of the variables Ymix, Yout, and/or yinv (which for consistency should probably be Yinv; case matters!) is of class uint8. The range of values that type can store is 0 to 2^8-1 = 255. You can check this using the class or whos functions.
The variable names you have used suggests to me that you may be trying to combine Yout and Yinv, like (1-k)*Yout + k*Yinv. If that's the case take a look at intlincomb from Image Processing Toolbox. See the last paragraph of the Description section of that documentation page for how this differs from simply multiplying by the proportions and combining the results.
1 Commento
Fabio Corres
il 18 Mar 2017
Image Analyst
il 18 Mar 2017
Try this instead of the for loop
Ymix = Yout .* yinv * k;
Now this may have none, some, or all values that are more than 255.
Then to clip to 255, you can do
Ymix = max(Ymix, 255);
Alternatively if you want to scale it so that the min is 0 and the max is 255, and then cast to uint8, you can do this:
Ymix = uint8(255 * mat2gray(Ymix));
Alternatively if you want to scale it so that the min is scaled and the max is 255, and then cast to uint8, you can do this:
Ymix = uint8(255 * Ymix / max(Ymix(:)));
What do you want to do?
Categorie
Scopri di più su Image Arithmetic in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!