필터 지우기
필터 지우기

Multible Pixel Values Doesn't Allow Bigger Than 255

조회 수: 11 (최근 30일)
Fabio Corres
Fabio Corres 2017년 3월 18일
답변: Image Analyst 2017년 3월 18일
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

채택된 답변

Walter Roberson
Walter Roberson 2017년 3월 18일
Ymix = zeros(m, n);
dYout = double(Yout);
dyinv = double(yinv);
dk = double(k);
for index1= 1 : m
for index2 = 1 : n
Ymix(index1,index2) = dYout(index1,index2)*dyinv(index1,index2)*dk;
end
end
The results can be greater than 255. You have to then figure out what that means and how you want to display the image.
Because Ymix will be double precision (needed to allow arbitrarily large or small values since your values could be greater than 1 or could be negative), if you were to image(Ymix) or imshow(Ymix) it would notice that the data was double precision and it would assume that the minimum value to display was 0.0 and that the maximum value to display was 1.0, and it would color any negative values the same as it colored 0.0 and it would color all values > 1.0 the same as it colored 1.0. That is how graphics on double precision values is defined.
You can use imagesc(Ymix) or imshow(Ymix, []) . That would tell it to examine Ymix and use the minimum value it found as being the first color and the maximum value it found as being the last color and to scale everything linearly between those. That can be useful, but it is not consistent between matrices: if in one matrix the maximum value was (say) 300 and in another matrix the maximum value happened to be (say) 350, then the value "128" that was originally half intensity would come out as 43% intensity in the first of the two matrices but would come out as 37% intensity in the second matrix. That would make it impossible to compare the two matrices by color.
Basically, doing this kind of pixel manipulation in double precision is only useful for intermediate matrices that will you will then multiply again by something that you are sure will scale them back to the range 0 to 255, at which point you would uint8() on the matrix to get something that can be displayed.
  댓글 수: 1
Fabio Corres
Fabio Corres 2017년 3월 18일
Oh i get it now thanks for the information it works

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

추가 답변 (2개)

Steven Lord
Steven Lord 2017년 3월 18일
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.

Image Analyst
Image Analyst 2017년 3월 18일
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?

Community Treasure Hunt

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

Start Hunting!

Translated by