I'm trying to use USGS DEMs in MATLAB but after reading it in with geotiffread, mapshow produces an error. Based on the documentation, I tried
[A, R] = geotiffread('NED_10340081')
figure
mapshow(A, R);
but I get
Error using mapshow
Expected input number 1, I or X or RGB, to be one of these types:
uint8, uint16, double, logical
Instead its type was single.
Error in validateMapRasterData>parseImageInputs (line 109)
validateattributes(A, {'uint8', 'uint16', 'double', 'logical'}, ...
Error in validateMapRasterData>validateImageComponent (line 93)
[A, R] = parseImageInputs(mapfcnname, dataArgs{:}, cmap, rules );
Error in validateMapRasterData (line 27)
[Z, SpatialRef] = validateImageComponent(mapfcnname, ...
Error in maprastershow (line 127)
[Z, SpatialRef, displayType, HGpairs] = ...
Error in mapshow (line 231)
h = showFcn(varargin{:});
My matrix A is of type single...is that the problem? and how do I fix this?
Here is a download link for the DEM http://snowserver.colorado.edu/pub/fromDominik/NED_10340081.zip
Thanks
PS I crossposted this at http://www.mathworks.com/matlabcentral/answers/38255-display-usgs-dem-using-geotiffread-and-mapshow
Specifying DisplayType is necessary because Matlab distinguishes "images" from continuous raster data. Matlab has an entire Image Processing Toolbox as well as a Mapping Toolbox with distinct functions in each that are often complimentary but come from different development backgrounds. Matlab supports "images" in logical, uint8, uint16, and double class types, and raster (grid) data in single and double.
Also your solution to use 'DisplayType','surface' only worked in your case because you had 'single' data. If, for example, you had created a geotiff image in ArcGis and then tried to read it into Matlab it would come in as int16 and you would get the same error when trying to use mapshow or geoshow, but the 'DisplayType','surface' would not work in this case because that DisplayType does not accept int16. Your solution to convert to double is more general.
I finally figured it out.
geotiffread gives a matrix type 'single' but mapshow defaults to show an image which only accepts type 'double' (and some others). So the solution here is to either:
A=double(A);
or
mapshow(A,R,'DisplayType','surface');
Related
I'm trying to display a montage of images in MATLAB, where each image is an N x M array and K images are stored as an N x M x K array.
MATLAB returns the errors:
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 240)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Error in montage (line 152)
hh = imshow(bigImage, displayRange,parentArgs{:});
These exact errors persist when I copy-paste and run the code supplied the MATLAB documentation for the montage function, included here:
img1 = imread('AT3_1m4_01.tif');
img2 = imread('AT3_1m4_02.tif');
img3 = imread('AT3_1m4_03.tif');
img4 = imread('AT3_1m4_04.tif');
multi = cat(3,img1,img2,img3,img4);
montage(multi);
This code is supposed to create a montage from an N x M x K array in the same manner as the original code I am troubleshooting, and fails to in the same manner.
Does anyone else receive these errors from this code? Can someone tell me how to adjust this code to produce a montage of images as demonstrated in the documentation example?
My guess is that this is a version error. Are you running Matlab 2018a? That is the version which the documentation is for. I would fancy a guess that an older version of Matlab used a different interface.
I would try typing
help montage
in your Matlab. Perhaps there are some addition tips there.
The documentation says
montage(I) displays all the frames of a multiframe image array I. A
multiframe image array can be a sequence of binary, grayscale, or
truecolor images. A binary or grayscale image sequence must be an
M-by-N-by-K or an M-by-N-by-1-by-K array. A truecolor image sequence
must be an M-by-N-by-3-by-K array.
however the M-by-N-by-K does not seem to work. But the M-by-N-by-1-by-K does.
Therefore
multi = cat(4,img1,img2,img3,img4);
tried this code
A=imread('1.jpg');
FaceDetector=vision.CascadeObjectDetector();
BBOX=step(FaceDetector,A);
B=insertObjectAnnotation(A,'rectangle',BBOX,'Face');
imshow(B),title('Detected Faces');
n=size(BBOX,1);
str_n=num2str(n);
str=strcat('number of detected faces are ',str_n);
disp(str);
this error show with me
Undefined function 'insertObjectAnnotation' for input arguments of type 'uint8'.
Error in Detected_faces (line 9)
B=insertObjectAnnotation(A,'rectangle',BBOX,'Face');
You just need to change the type of your image.
A type must be uint8 and the "insertObjectAnnotation" function only takes different inputs.
Please try:
A=imread('1.jpg');
FaceDetector=vision.CascadeObjectDetector();
BBOX=step(FaceDetector,A);
B=insertObjectAnnotation(rgb2gray(A),'rectangle',BBOX,'Face');
Actually, I tried this:
I = imread('coins.png');
FaceDetector=vision.CascadeObjectDetector();
BBOX=step(FaceDetector,I);
B=insertObjectAnnotation(I,'rectangle',BBOX,'Face');
And I is uint8, and it worked.
Using your dataset, it worked just fine. See Image output.
I'm using regionprops() but I'm getting an error with the following code:
J = imread('E:\Canopy New Exp\Data Set\input.jpg');
I = rgb2gray(J);
BW = regionprops(J,'basic');
stats = regionprops('table',BW,'Centroid',...
'MajorAxisLength','MinorAxisLength');
centers = stats.Centroid;
diameters = mean([stats.MajorAxisLength stats.MinorAxisLength],2);
radii = diameters/2;
hold on;
viscircles(centers,radii);
hold off;
But I'm getting the following error:
Error using regionprops
Expected input number 1, L, to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64
Instead its type was char.
Error in regionprops (line 142)
validateattributes(L, {'numeric'}, ...
Error in Untitled (line 8)
stats = regionprops('table',BW,'Centroid',...
Any suggestions?
Thanks in advance!
You are doing regionprops twice, and the second time with 'table' as the first parameter. regionprops expects an image (black and white, connected components, or labelled) as the first parameter, so that is why you are getting the error type char.
Instead feed in a black and white (binary) image to one call of regionprops, and that should be done:
thresh = graythresh(I); % get a threshold (you could just pick one)
I_BW = im2bw(I,thresh); % make the image binary with the given threshold
stats = regionprops(I_BW,'basic'); % do regionprops on the thresholded image
You can also do regionprops with 2 image parameters, one to show the regions in the other, so instead of the regionprops call above, you could possibly try:
stats = regionprops(I_BW, J, 'basic');
regionprops outputs an object so in the third line of the above code sample you call it on J, an image, which is fine and returns an appropriate object BW. But then in the following line you call it again on the BW object and that's where the error comes from. It isn't meaningful to call it twice on successive objects, but it's more likely that that wasn't your intention and you meant to binarise the image first with im2bw.
When you read the error messages output by matlab be aware that the bottom line is the line in your code where the error occurred. If you are supplying the wrong kind of input to one of matlab's builtin functions (this is by far the most common kind of error in my own experience) then it won't be until you've gone deeper into matlab's internal functions that the error manifests.
So reading the error report from the bottom upwards you go deeper into the call stack until the top line, which is the 'actual' error. That top line gives you the cause of the conflict, which is half the story. You can then take that half back to the line of your code to see why it happened and how to fix it.
You're probably feeding it a RGB array NxMx3. regionprops takes a NxM binary array according to the documentation.
Why is that whenever I try to use detectSURFFeatures(img) with a binary image in matlab gives me proper points but whenever I use detectMSERFeatures(img) with the same binary image gives me error instead of pointing some valid regions?
ERROR:
Error using detectMSERFeatures
Expected input number 1, I, to be one of these types:
uint8, int16, uint16, single, double
Instead its type was logical.
Error in detectMSERFeatures>parseInputs (line 75)
validateattributes(I,{'uint8', 'int16', 'uint16', ...
Error in detectMSERFeatures (line 64)
[Iu8, params] = parseInputs(I,varargin{:});
Try this:
make image 2 double first by using img=im2double(img);
then feed it to MSER
detectMSERFeatures(img)
detectMSERFeatures does not accept logical inputs, as stated in the documentation and in the error you are receiving. detectSURFFeatures does. I don't know if there's a specific reason why, as I'm not familiar with the limitations of the different algorithms.
You could simply convert your binary image to one of the types listed, and run MSER on it:
detectMSERFeatures(double(img));
How to convert .dcm(dicom) image to .bmp format.
I have tried this, but its not working for me.
000000.dcm is a medical lung image (size 6 MB)
dcmimg = dicomread('000000.dcm');
>> imshow(dcmimg);
DCM image read in dcmimg
imwrite(dcmimg, 'myfile.bmp');
Getting error:
Error using writebmp (line 15)
Expected X to be one of these types:
logical, uint8, single, double
Instead its type was uint16.
Error in imwrite (line 477)
feval(fmt_s.write, data, map, filename, paramPairs{:});
I am not understanding these errors, What's going wrong. Help me out, Thank You.
Dicom uses unsigned 16 bit integers. The function that writes .bmp files expects a different data type, as explained by the error message. This suggests that the following should work:
imwrite(double(dcmimg), 'myFile.bmp');
By explicitly converting the data type to double you should get rid of the error. Actually single might be enough... It too can represent 16 bit integers without loss of precision.