I am working with few Dicom files and when i try to use dicomread('filename.dcm') in MATLAB it gives the following error:
Error using dicomread>processOffsetTable (line 943)
The compressed pixel data is missing item delimiters.
Error in dicomread>processEncapsulatedPixels (line 858)
[offsetTable, offset] = processOffsetTable(metadata);
Error in dicomread>newDicomread (line 232)
X = processEncapsulatedPixels(metadata, frames);
Error in dicomread (line 86)
[X, map, alpha, overlays] = newDicomread(msgname, frames, useVRHeuristic);
I can view this same file in dicom viewing Softwares like onis, di com viewer, Sante Dicom etc.., but when i use dicomread I cannot see see them and get this error
I have so many images of this same format and cannot start from the beginning again, Is there any way I can use this file and view it.
Refer this online help.
It is common in DICOM world that not all data sets fully comply with DICOM. Most applications (you mentioned in your question) handle the non-compliant part with assumptions and workarounds based on experience and imagination.
Try setting TF to false to read these files.
Also note the list of supported transfer syntax:
Little-endian, implicit VR, uncompressed
Little-endian, explicit VR, uncompressed
Big-endian, explicit VR, uncompressed
JPEG (lossy or lossless)
JPEG2000 (lossy or lossless)
Run-length Encoding (RLE)
GE implicit VR, LE with uncompressed BE pixels (1.2.840.113619.5.2)
Check your input image is compressed with one of the above.
Related
The Matlab app imageLabeler is supposed to support the following format:
imageLabeler(imgStore)
I have an imgStore, defined as follows:
imds = imageDatastore(cellArrayOfImageFilenames);
imgStore = transform(imds, #(x)demosaic(x,'rggb'));
I have to do this, because my images are stored as bayer encoded images, and this is the only way I've figured out to get the imgStore to return these images as 3 channel RGB images. However, when I try and initalize imageLabeler, I get this error:
>> imageLabeler(imgStore)
Error using imageLabelerInternal
Expected input name to be one of these types:
char
Instead its type was matlab.io.datastore.TransformedDatastore.
Error in vision.internal.imageLabeler.imageLabelerInternal
Error in imageLabeler (line 58)
vision.internal.imageLabeler.imageLabelerInternal(varargin{:});
TLDR:
How do I get imageLabeler to handle my bayer encoded images?
The way to fix this, is with the imageDatastore 'ReadFcn' parameter. The documentation for imageDatastore explicity tells you to NOT do this, as it slows down Neural Network stuff. Here's the Matlab doc text:
Using ReadFcn to transform or pre-process 2-D images is not
recommended. For file formats recognized by imformats, specifying
ReadFcn slows down the performance of imageDatastore. For more
efficient ways to transform and pre-process images, see Preprocess
Images for Deep Learning (Deep Learning Toolbox).
So, all that said, here's the workaround:
imgStore = imageDatastore(cellArrayOfImageFilenames ...
, 'ReadFcn', #(x)demosaic(imread(x),'rggb')));
I have some PPM images (stereo) that I read with imread() and I want to save the same images in JPEG with different Quality factors.
Here is my code.
%Read PPM image
L = imread(filename_L);
%Create JPEG Q85 from PPM
filename_L85 = strcat(filename_L,'_ppm_to_jpeg.jpg');
imwrite(L,filename_L85,'JPEG','Quality',85);
And here the error I get.
Error using imwrite>parse_inputs (line 528)
The colormap should have three columns.
Error in imwrite (line 418)
[data, map, filename, format, paramPairs] = parse_inputs(varargin{:});
Error in testFinale (line 75)
imwrite(L,filename_L85,'JPEG','Quality',85);
How can I write JPEG images previously read in PPM format?
Thanks
Could it be that is just has to do with your case of 'JPEG', the documentation of imwrite specifies parameters for file type as lowercase.
Apart from that you might not even need it as the file type is derived from the extension which in this case is set explicitly to .jpg already.
So you might either go for:
imwrite(L,filename_L85,'jpeg','Quality',85);
or perhaps even easier:
imwrite(L,filename_L85,'Quality',85);
I have downloaded a btf file (big tiff) from the links below, how can I read it and "imshow" it? is there a way to convert it to tiff format as the btf is not that common?
Link:
https://drive.google.com/file/d/0ByhuP_NuuARtSW9aeTdPUTlRdWM/view?usp=drive_web
http://www.photomacrography.net/forum/viewtopic.php?t=28990&sid=cca737a2e0bc7ea3e2e41f0d6e75f5a9
I used this code:
t = Tiff('d:/Image_687.btf','w8');
imageData = read(t);
and got this error:
Error using tifflib
Unable to retrieve PhotometricInterpretation.
Error in Tiff/getTag (line 838)
tagValue = tifflib('getField',obj.FileID,Tiff.TagID.(tagId));
Error in Tiff/read (line 1487)
photo = obj.getTag('Photometric');
Error in Untitled2 (line 2)
imageData = read(t);
The real issue with your code is the second parameter that you have passed to Tiff. As the documentation states, the second parameter indicates in what mode to open the file. You have specified w8 which the documentation states is:
open TIFF file for writing a BigTIFF file; discard existing contents.
This means that it is deleting your image before you even start! If you want to use the Tiff class, you'll want to either use no second parameter or the r parameter to open the file for reading.
t = Tiff('Image_687.btf');
t = Tiff('Image_687.btf', 'r');
That being said, in general it is better to try to load it with a higher level function such as imread. The Tiff class is a much lower-level function that can be a little harder to manipulate but may provide some needed specialty functionality.
im = imread('Image_687.btf');
size(im)
3072 4080 3
I had to do a little manipulation for display because the RGB values weren't between 0 and 255
im = double(im);
im = uint8(255 * im ./ max(im(:)));
imshow(im);
I have a singe image.tiff file, a video sequence exported as 32 bit tiff. I would like to open it as an image stack in MATLAB, and be able to navigate frame by frame. I believe implay() is the way to do this in matlab. If I try this I get "Error occurred while attempting to read file: image.tiff Details of error: Incorrect chunk size information in AVI file." Does implay() only work with the .avi format? do I need to covert this 32 tiff to a .avi before i can use implay()? or is there maybe some other (non-implay()) way of opening this as a stack?
Thanks
You could try to create an image stack and use implay to view it. The function accepts multiple types of arguments, for grayscale images it should be provided with an array of size N x M x K where K is the number of frames, (N,M) is the image size. For color images an array of size NxMx3xK is expected.
To create the array for the case with multiple files, each containing a frame you have multiple options, the simplest is probably to use the cat function for concatenation:
image_stack = [];
for i = 1: num_frames
curr_image = imread(sprintf('frame_%04d_color.tif', i));
image_stack = cat(4, image_stack, curr_image);
end
implay(image_stack);
This solution is a bit slower, than if the image_stack is allocated beforehand though.
For your case with a single TIFF file, the frames need to be extracted in a manner suitable for the storage format, but this is a separate problem from the video replay.
i am trying to import a .tif image into matlab with the following code
>> aa = imread('house.tif');
i get the error
Error using rtifc
TIFF library error: '_TIFFVSetField: C:\Users\user\Documents\MATLAB\house.tif: Null count
for "Tag 34022" (type 1, writecount -3, passcount 1).'.
Error in readtif (line 49)
[X, map, details] = rtifc(args);
Error in imread (line 434)
[X, map] = feval(fmt_s.read, filename, extraArgs{:});
as i am using matlab for the first time in my life i really have no idea what this error means. Please help is required in this matter.
MATLAB R2012b has a bug and it cannot read TIFF files properly. More information can be found here: http://www.mathworks.com/matlabcentral/newsreader/view_thread/326232
Probably Matlab does not support the specific type of tif. In Matlab's defence, tif is not an easy file-format to read. It supports plenty of compression schemes, multiple pages and who knows what. I'd convert the tif to png and go with that.
Update: A quick Google search revealed that "rtifc" is a Matlab mex-wrapper around libtiff. Your error appears to come from libtiff. If the latter can't read it, your tif will probably be problematic for a lot of other applications too.
Another thing you could try is use the implementation tiffread from François Nedelec's group at EMBL. http://www.embl.de/ExternalInfo/nedelec/misc/matlab/tiffread29.m. It's heavily used by biology folks all over the world. I've been using it for many years.