What is the different if the value of the image is 0 and 1, and if the value of the image is 0 and 255?
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dayangku Nur Faizah Pengiran Mohamad
il 16 Nov 2023
Modificato: DGM
il 16 Nov 2023
Anyone can explain me on details what is exactly the different if the value of the image is 0 and 1,
then another image is 0 and 255? Is the same idea? Black and white?
0 Commenti
Risposta accettata
Cris LaPierre
il 16 Nov 2023
The range of values, and more particularly, what value corresponds to white, is determined by the data type of your image. What are the data types of your images? If 255 is white, then it is likely you are working with an 8-bit image. A scale of 0-1 tends to be the case when you have converted your image to single or double in MATLAB.
Here, both are binary images. 0 corresponds to black, and 1 or 255 correspond to white.
6 Commenti
DGM
il 16 Nov 2023
Modificato: DGM
il 16 Nov 2023
Do not save binary images as JPG
The content will be damaged, the datatype will be altered, and the filesize will be larger than using a lossless format like PNG. There's no reason to use JPG for a binarized image.
JPG is not lossless, and this isn't Photoshop or GIMP, where you're saving 90% 4:4:4 JPGs. That's not an option. Unless you have carefully considered the damage caused by using a low-quality 4:2:0 downsampled JPG, and you don't intend to ever do any further technical processing of an image, just don't use JPG for anything. That includes when you save figures and plots.
Another example:
% a logical image
A = imread('1qqq.jpg')>128;
imshow(A)
% save as JPG, read back
fname1 = 'junk.jpg';
imwrite(A,fname1);
B1 = imread(fname1);
% the image class is now uint8
% and the values are spread away from black/white
imhist(B1)
ylim([0 500])
% so we'd have to re-binarize it _every single time_
B1 = B1 > 128;
% save as PNG, read back
fname2 = 'junk.png';
imwrite(A,fname2);
B2 = imread(fname2);
% the image class is unchanged
% the values are exactly the same
% we don't have to do anything.
isequal(A,B2)
% the damaged JPG is 9x as large as a perfect PNG
S1 = imfinfo(fname1);
S2 = imfinfo(fname2);
sizerat = S1.FileSize/S2.FileSize
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!