필터 지우기
필터 지우기

image arithmetic result not the same

조회 수: 2 (최근 30일)
Aaron Connell
Aaron Connell 2018년 2월 26일
댓글: Aaron Connell 2018년 2월 26일
Good evening, I have a question about image arithmetic. Below is some code that reads in a grayscale image and performs arithmetic on it. I want to know why the modified image does not look the same when we essentially divided the image pixels by 64 and then multiplied the result by 64. the resulting image should have been identical. Below is the image of the result:
b=imread('blocks.jpg');
class(b); %shows it is a uint8 image
b2=(b/64)*64;
subplot(1,2,1)
imshow(b)
title('original image')
subplot(1,2,2)
imshow(b2)
title('modified image')

채택된 답변

Walter Roberson
Walter Roberson 2018년 2월 26일
>> uint8(65)/64
ans =
uint8
1
>> uint8(63)/64
ans =
uint8
1
we deduce from this that when you do arithmetic on an int8 or uint8, the result is always as if you had done the arithmetic in double precision, then rounded it, and converted back to the data type.
>> uint8(round(double(uint8(65))/double(64)))
ans =
uint8
1
>> uint8(round(double(uint8(63))/double(64)))
ans =
uint8
1

추가 답변 (1개)

Steven Lord
Steven Lord 2018년 2월 26일
How many unique values can the results of (b/64)*64 take on?
b = intmin('int8'):intmax('int8');
b2 = (b/64);
unique(b2)
Read this page for a description of why the list of unique values in b2 is so short.
  댓글 수: 1
Aaron Connell
Aaron Connell 2018년 2월 26일
Thank you very much I had no idea about the unique function. That gave me a clear answer.

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

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by