HI
I wrote a program that use to work (swear to god) and has stopped from working. this code takes a series of BMPs and convert them into avi file. this is the code:
path4avi='C:/FadeOutMask/'; %dont forget the '/' in the end of the path
pathOfFrames='C:/FadeOutMask/';
NumberOfFiles=1;
NumberOfFrames=10;
%1:1:(NumberOfFiles)
for i=0:1:(NumberOfFiles-1)
FileName=strcat(path4avi,'FadeMaskAsael',int2str(i),'.avi') %the generated file
aviobj = avifile(FileName,'compression','None');
aviobj.fps=10;
for j=0:1:(NumberOfFrames-1)
Frame=strcat(pathOfFrames,'MaskFade',int2str(i*10+j),'.bmp') %not a good name for thedirectory
[Fa,map]=imread(Frame);
imshow(Fa,map);
F=getframe();
aviobj=addframe(aviobj,F)
end
aviobj=close(aviobj);
end
And this is the error I get:
??? Error using ==> checkDisplayRange at 22
HIGH must be greater than LOW.
Error in ==> imageDisplayValidateParams at 57
common_args.DisplayRange = checkDisplayRange(common_args.DisplayRange,mfilename);
Error in ==> imageDisplayParseInputs at 79
common_args = imageDisplayValidateParams(common_args);
Error in ==> imshow at 199
[common_args,specific_args] = ...
Error in ==> ConverterDosenWorkd at 19
imshow(Fa,map);
for some reason I cant put it as code segments. sorry
thank you
Ariel
Are the BMP images indexed? I think the map parameter only applies to images with indexed color maps.
The only way I am able to reproduce the error that you get is when map is a two-element vector where the first element is greater than the second. Note first that the function IMSHOW can be called with the following syntax:
imshow(I,[low high]);
In which I is a grayscale image and low and high specify the display range for the pixel intensities. The extra argument is ignored when I is an RGB image, but even then the value of high must be greater than the value of low or an error is thrown (the one you see above).
What's confusing is why map would be a two-element vector. When loading an image with IMREAD, the map output will either be empty (if the image is not an indexed image) or it will be an N-by-3 color map. I can't think of a situation where the built-in IMREAD would return a map argument with just 2 elements.
Based on the fact that you said it was working, and now suddenly isn't, I would suggest first checking to see if you have inadvertently created an m-file somewhere with the name imread. Doing so could cause that new imread function to be called instead of the built-in one, giving you different outputs than you expect.
Related
I created binarized images by using the Otsu methode in Matlab and cut out parts of the resulting image using a function. Now i want to take a look at these images with the VolumeViewer command. I know the x,y and z dimensions of the resulting imgages. I currently run this code doing it(excluding the volumeViewerwhich happens after the loop):
files= {'C3\C3_000mal_550_539_527.raw';...
};
for i=1:numel(files)
Image = fopen(files{i},'r');
ImageData{i} = fread(Image,Inf,'uint16=>uint16');
ImageData{i} = reshape(ImageData{i},550,539,[]);
fclose(openedCrystalImage);
end
Using this code runs into the following error using reshape:
Error using reshape
Product of known dimensions, 296450, not divisible into total number of elements, 78114575.
I did the maths and 550*539=296450 and 296450 * 527=156229150: If we divide the last number by the number of elements it equals 2 and thus is divisible into the total number of elements. In my opinion the reshape function is not able to find the size of the last dimension or defines it as 1.
Defining the size of z also results in an error suggesting using the brackets [], so the function can find it.
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size
for that dimension.
Now to the weird part. This code works for another set of images, with diffrent sizes of the x,y and z ranges. So don´t know where the issue lies to be frank. So i would really appreciate and Answer to my question
I figured it out. The error lies here:
ImageData{i} = fread(Image,Inf,'uint16=>uint16');
Apparently by saving them as .raw before it converts the image to an 8 bit file rather than 16 bits it had before. Therefore, my dimension is double the size of the number of elements. With this alteration it works:
ImageData{i} = fread(Image,Inf,'uint8=>uint8');
The reason i was able to look at the other pictures was that the z range was divisble by 2.
So the reshape function was not the problem but size of the integer data while creating the array for the variable ImageData.
P.S. I just started out programming so the accuracy in the answer should be taken with a grain of salt
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.
I am getting error in my Matlab code. I am using R2009b version
Frame index must be a numeric value greater than zero and less
than or equal to the number of frames in the file.
Error in ==> mmreader.read at 74
videoFrames = read(getImpl(obj), index);
Error in ==> testing at 10
Ii=read(mov,k*10);
Just a hunch, but I'm guessing that your frame index is not:
a numeric value greater than zero and less than or equal to the number
of frames in the file.
MATLAB is telling you that the error is happening in mmreader.read, and it is happening when you call mmreader.read at this point in your file testing:
Ii=read(mov,k*10);
If your movie reader object mov contains less than k*10 frames, or if k is zero or a negative number, you are asking MATLAB to do something impossible.
These sort of errors can be easily tracked down by typing dbstop if error at the command line, which means that when there is an error you enter debug mode. At this point you can then check what the value of k is, and also the number of available frames in mov.
I am trying to find log of base 10 of each pixel of an image in matlab using following code
m1 = imread('owl','pgm');
for x = 1:size(m1,1)
for y = 1:size(m1,2)
m1(x,y) = log10(m1(x,y));
end
end
here m1 is a 2-D array of order 221 X 201.
but I am facing this error
??? Undefined function or method 'log2' for input arguments of type 'uint8'.
Error in ==> log10 at 20
y = log2(x);
Error in ==> q2 at 38
m1(x,y) = log10(m1(x,y));
but when I debug log function using following code
fprintf('log of 190 is %d', log10(190));
it gives me right output I dont know what happened when I use the same code in the loop.
The error message tells you what the problem is, you've tried to apply the log10 function to a value of type uint8 and the function is not defined for that type of number. What you haven't realised is that imread, when an image file meets certain criteria (read the documentation for what those criteria are) will capture the pixel data into an array of uint8s, not real numbers.
If you want to take the logarithm of a uint8 you'll either have to define a logarithm function of your own which takes such inputs, or, more straightforward, cast the uint8 to a type which log10 is happy with. For example, you could write:
log10(double(m1(x,y)))
And by now you'll have realised why your diagnostic test didn't tell you anything useful, when you execute the command log10(190) Matlab, by default, decides that 190 is of type double and computes the logarithm without complaint. log10(uint8(190)) tells a different story.
I tried to read an image and display it but i faced an error and i didn't understand it.can any one help me please, note that i use MATLAB R2010a, and the display below is the type of error.
>> imread('tas.jpg');
>> imshow('tas.jpg');
??? Attempt to call constructor image with incorrect letter case.
**Error in ==> basicImageDisplay at 9
hh = image(xdata,ydata,cdata, ...
Error in ==> imshow at 246
hh = basicImageDisplay(fig_handle,ax_handle,...**
I = imread('tas.jpg');
imshow(I);
The imread function reads the file and converts it to a RGB matrix of pixels. This is stored on the variable I. Then, you can call imshow passing this RGB matrix as a parameter ;)
edit you can call imshow with the filename as well, but it's not that useful because it does not return the matrix you will later use for processing. And as the error is thrown only on imshow, I'm guessing the imread function, for some reason, is working.
If not, just double check if the image is on the actual directory or in a directory on the path, or if it is not corrupted.
This might be the reason (from the below thread):
Reason: "current directory folder name is match with built-in function in matlab library and gives the error - Attempt to call constructor image with incorrect letter case".
Solution: change the folder name with unique name.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/256922