Error in displaying .TIF images in MATLAB
Afficher commentaires plus anciens
I tried to display a .tif image in MATLAB. The system is able to read it, but not able to display it.
pet=imread('13.tif');
imshow(pet);
Error using imageDisplayValidateParams>validateCData (line 113)
Multi-plane image inputs must be RGB images of size MxNx3.
Error in imageDisplayValidateParams (line 27)
common_args.CData = validateCData(common_args.CData,image_type);
Error in imageDisplayParseInputs (line 78)
common_args = imageDisplayValidateParams(common_args);
Error in imshow (line 219)
[common_args,specific_args] = ...
16 commentaires
Eric Auth
le 5 Mar 2018
Hi Gee,
Were you ever able to solve this problem? I am getting a similar error when trying to view a .TIF file. I have been able to read .TIFF images that were converted from RAW images, however when I use adobe to convert screen captures from my camera's video mode, Matlab does not seem to like the image. Let me know. Thanks
Walter Roberson
le 5 Mar 2018
Are the TIFF written as CMYK or as RGBA or are they multispectral?
Eric Auth
le 25 Mar 2018
How would I check this? The .TIFF files are .ARW (raw) files from a Sony camera converted to .TIFF by the program dcraw. The .TIF are video screenshots from Adobe PremierePro.
Walter Roberson
le 25 Mar 2018
What are the options you are using for dcraw ?
Eric Auth
le 26 Mar 2018
"-6: Write 16-bit instead of 8-bit" and "-T: Write TIFF instead of PPM"
Walter Roberson
le 26 Mar 2018
I think I would need to see the TIFF metadata. As a first pass could I see the output of imfinfo() applied to the tiff ?
Eric Auth
le 26 Mar 2018
Filename: 'C:\Users\lenovo\Documents\MATLAB\BB_0.1.tiff'
FileModDate: '27-Nov-2017 22:08:51'
FileSize: 60545788
Format: 'tif'
FormatVersion: []
Width: 5496
Height: 3672
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: [73 73 42 0]
ByteOrder: 'little-endian'
NewSubFileType: 0
BitsPerSample: [8 8 8]
Compression: 'Uncompressed'
PhotometricInterpretation: 'RGB'
StripOffsets: 1852
SamplesPerPixel: 3
RowsPerStrip: 3672
StripByteCounts: 60543936
XResolution: 300
YResolution: 300
ResolutionUnit: 'Inch'
Colormap: []
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.01
MaxSampleValue: [255 255 255]
MinSampleValue: [0 0 0]
Thresholding: 1
Offset: 10
ImageDescription: ' '
Make: 'Sony'
Model: 'DSC-RX10M3'
Software: 'dcraw v9.27'
DateTime: '2017:11:27 18:43:07'
Artist: ''
DigitalCamera: [1×1 struct]
ICCProfileOffset: 1376
Eric Auth
le 26 Mar 2018
By comparison, what we have for the .TIF from the video/AdobePremierePro:
Filename: 'C:\Users\lenovo\Documents\MATLAB\Chopstick.tif'
FileModDate: '18-Feb-2018 21:58:24'
FileSize: 8307822
Format: 'tif'
FormatVersion: []
Width: 1920
Height: 1080
BitDepth: 32
ColorType: 'truecolor'
FormatSignature: [73 73 42 0]
ByteOrder: 'little-endian'
NewSubFileType: 0
BitsPerSample: [8 8 8 8]
Compression: 'Uncompressed'
PhotometricInterpretation: 'RGB'
StripOffsets: [1×1080 double]
SamplesPerPixel: 4
RowsPerStrip: 1
StripByteCounts: [1×1080 double]
XResolution: []
YResolution: []
ResolutionUnit: 'Inch'
Colormap: []
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.01
MaxSampleValue: [255 255 255 255]
MinSampleValue: [0 0 0 0]
Thresholding: 1
Offset: 8303182
DateTime: '2018:02:18 16:58:24'
XMP: '<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>…'
Photoshop: [56 66 73 77 4 37 0 0 0 0 0 16 212 29 140 217 143 0 178 4 233 128 9 152 236 248 66 126]
Walter Roberson
le 26 Mar 2018
I am confused. The headers for BB_0.1.tiff are those for an RGB image with 8 bits per channel, 5496 wide and 3672 high. I see no evidence in the headers for it that it would return 4 planes. This file was written by dcraw.
On the other hand the headers for Chopstick.tif show four channels of 8 bits per channel, 1920 wide and 1080 high. It is not immediately clear to me what the 4th channel is, but alpha would make the most sense.
Eric Auth
le 27 Mar 2018
Thanks a lot! By opening the screenshot from premeirepro in Adobe Photoshop, you are able to save as a .TIFF and there is an option to "remove alpha channels". After doing this I am able to open the screenshot in Matlab.
Walter Roberson
le 27 Mar 2018
I suspect that if you were to use imread() and discard the 4th plane then that would be RGB.
Eric Auth
le 28 Mar 2018
Is there an easy way to do that? That would make the process much more efficient
Walter Roberson
le 28 Mar 2018
tiff_image = imread('AppropriateFileName.tif');
if ndims(tiff_image) > 3
error('got tiff image with more than 3 dimensions???');
end
if size(tiff_image,3) == 4
tiff_image = tiff_image(:,:,1:3);
elseif size(tiff_image,3) == 1
tiff_image = tiff_image(:,:,[1 1 1]); %grayscale to rgb
elseif size(tiff_image,3) ~= 3
error('expected tiff image to have 1 channel, or 3 channels, or 4 channels, got %d\n', size(tiff_image,3));
end
Walter Roberson
le 28 Mar 2018
Note that this can be made much simpler if you assume that all of the data is the same:
tiff_image = imread('AppropriateFileName.tif');
tiff_image = tiff_image(:,:,1:3);
Soumyadip Ray Cahudhuri
le 31 Juil 2019
this is my code
I=imread('pout.tif');
imshow(I)
figure
imshow(I>220)
this is thr error
Error using images.internal.imageDisplayValidateParams>validateCData (line 115)
Multi-plane image inputs must be RGB images of size MxNx3.
Error in images.internal.imageDisplayValidateParams (line 27)
common_args.CData = validateCData(common_args.CData,image_type);
Error in images.internal.imageDisplayParseInputs (line 78)
common_args = images.internal.imageDisplayValidateParams(common_args);
Error in imshow (line 223)
[common_args,specific_args] = ...
Error in xd (line 2)
imshow(I)
what is the solution ?
Walter Roberson
le 31 Juil 2019
Show us size(I) and imfinfo('pout.tif')
Réponses (1)
Walter Roberson
le 5 Jan 2016
0 votes
What does size(pet) report? If it shows a 4 dimensional image, and you have the Image Processing Toolkit, try implay(pet)
3 commentaires
Gee Cheng Mun
le 6 Jan 2016
Modifié(e) : Gee Cheng Mun
le 6 Jan 2016
Ronnie II Concepcion
le 17 Avr 2020
Hi! I am trying to extract RGB channels from a colored picture and the resulting size and data type of each RGB component is MxNx7 uint8. I need to change the size to MxNx3. I think we have the same challenge. May I know how you resolved it? Thanks.
Walter Roberson
le 17 Avr 2020
Please show imfinfo() of the file.
Possibly the code I showed above would work,
tiff_image = imread('AppropriateFileName.tif');
tiff_image = tiff_image(:,:,1:3);
However, in my experience, TIFF with 7 channels are typically multispectra and do not necessarily have RGB or the RGB might not be the first three channels. I have found that most people who have TIFF with 7 channels want to synthesize an RGB image from multispectra data, typically hoping to include two channels of infrared from satellites.
Catégories
En savoir plus sur Images dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!