can image tiff convert to grayscale

조회 수: 14 (최근 30일)
bozheng
bozheng 2024년 4월 20일
편집: Walter Roberson 2024년 4월 20일
as title
i have pictue which file is tiff but it is flase coding about convert (Image file cannot be uploaded)
i read the image and "gray_image = rgb2gray(image)"
but it is error what i should do
thanks Ur reading and answering

채택된 답변

Walter Roberson
Walter Roberson 2024년 4월 20일
편집: Walter Roberson 2024년 4월 20일
zipname = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1674421/sample.zip';
tfile = fullfile(tempdir(), 'sample.zip');
filestr = urlwrite(zipname, tfile);
filenames = unzip(filestr);
imgname = filenames{1};
info = imfinfo(imgname)
info = struct with fields:
Filename: '/users/mss.system.p5sjk/eot i.tiff' FileModDate: '20-Apr-2024 11:03:54' FileSize: 191826 Format: 'tif' FormatVersion: [] Width: 652 Height: 97 BitDepth: 32 ColorType: 'truecolor' FormatSignature: [73 73 42 0] ByteOrder: 'little-endian' NewSubFileType: 0 BitsPerSample: [8 8 8 8] Compression: 'LZW' PhotometricInterpretation: 'RGB' StripOffsets: [8 7551 15132 22767 30420 38017 45641 53249 60998 68674 76415 84188 92015 100004 107793 115624 123518 131472 139588 147599 155729 ... ] (1x25 double) SamplesPerPixel: 4 RowsPerStrip: 4 StripByteCounts: [7543 7581 7635 7653 7597 7624 7608 7749 7676 7741 7773 7827 7989 7789 7831 7894 7954 8116 8011 8130 8226 8304 8437 8541 2166] XResolution: 96 YResolution: 96 ResolutionUnit: 'Inch' Colormap: [] PlanarConfiguration: 'Chunky' TileWidth: [] TileLength: [] TileOffsets: [] TileByteCounts: [] Orientation: 1 FillOrder: 1 GrayResponseUnit: 0.0100 MaxSampleValue: [255 255 255 255] MinSampleValue: [0 0 0 0] Thresholding: 1 Offset: 191404 Predictor: 'Horizontal differencing' ExtraSamples: 2
%ExtraSamples of 2 indicates Unassociated Alpha Values
img = imread(imgname);
rgb = img(:,:,1:3) .* img(:,:,4); %take into account the alpha
gray_image = rgb2gray(rgb);
imshow(rgb); title('rgb')
imshow(gray_image); title('gray')

추가 답변 (1개)

Image Analyst
Image Analyst 2024년 4월 20일
image is a built-in function. Do not use it as the name of your variable. Zip up your image and attach the zip file with the paperclip icon.

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by