uint8 vs int8 in imshow
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Dani D
am 12 Mär. 2016
Bearbeitet: DGM
am 12 Jun. 2024
Hello, What is difference between these? When i use int8 , the most of pixel been 127 and when i use uint8 the problem is solve.
I=imread('cameraman.tif');
I = uint8(I);
imshow(I);
I=imread('cameraman.tif');
I = int8(I);
imshow(I);
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 12 Mär. 2016
When you give int8() a value that is greater than 127, then it "saturates" and returns 127. A lot of your input values are greater than 127 so they are "saturating" at 127.
The same kind of thing happens for uint8 if you give it a value greater than 255: it saturates at 255.
0 Kommentare
Weitere Antworten (1)
DGM
am 27 Nov. 2023
Bearbeitet: DGM
am 12 Jun. 2024
Imshow() is odd in that it does actually support int8 images. It seems most other IPT tools which are class-sensitive don't. As usual though, the image needs to be properly-scaled for its class in order to display as expected.
The data needs to be rescaled as appropriate when casting in order for the image to be treated as intended. As Walter explained, simply casting a uint8() array using int8() will simply result in truncation without otherwise scaling or shifting the data. Consider the case with uint16 -> int16 conversion:
inpict = imread('cameraman16.png'); % uint16
A = int16(inpict); % half the data is truncated
imshow(A,'border','tight')
B = im2int16(inpict); % rescaled/offset as needed
imshow(B,'border','tight')
Why did I do this example with uint16/int16 instead of uint8/int8? Well remember that I said int8 support is an oddity in IPT? Yeah. There is no such im2int8() tool like there is for 16 bit images. You would either have to do it yourself:
inpict = imread('cameraman16.png'); % uint8 (could be any other class)
ir = getrangefromclass(inpict);
or = [-128 127];
scalefactor = diff(or)/diff(ir);
C = int8(round((double(inpict) - ir(1))*scalefactor) + or(1)); % int8
imshow(C,'border','tight')
... but there's no need to reinvent that wheel every time. MIMT imcast() supports int8, and it offers other practical conveniences.
% supports
% uint8,uint16,uint32,uint64,
% int8,int16,int32,int64,
% double,single,logical
outpict = imcast(inpict,'int8');
Either way, a workflow centered around int8 working images is going to be a huge hassle with no obvious benefit.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Get Started with Image Processing Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!