matlab size function throw an exception - image

I'm trying to get the size of an image in matlab, here is the code:
img = imread('folder\image1.jpg');
size(img);
I'm getting this error :
"Subscript indices must either be real positive integers or logicals"
I dont know why this happens, any help to know the issue would be appreciated
Thanks,

Judging from your comments your error occurs because you overloaded the size function with a variable.

Related

dlib: extract_histogram_descriptors inside extract_highdim_face_lbp_descriptors returns vector with zeros

I'm trying to extract this features, but it is returning a vector with all zeros. I called the function dlib::extract_highdim_face_lbp_descriptors and followed the code and it seems that is extract_histogram_descriptors is what it is returning zeros.
So I hope anyone can help, it would be highly appreciated.
Thanks
This are the important lines of my code:
std::vector features;
dlib::array2d<unsigned char> grayFace;
dlib::assign_image(grayFace, face);
dlib::extract_highdim_face_lbp_descriptors<dlib::array2d<unsigned char>, double>(grayFace, shape, features);
face is an array2D containing the recognized face, shape is of type dlib::full_object_detection.
I have also check that grayFace and shape are correct.
Ok, finally I could solve this problem, I post the answer in case someone has the same problem.
The thing is that as first argument, dlib::extract_highdim_face_lbp_descriptors expects the hole frame image, not just the found face which is what I was given to it.

MATLAB ConnectedComponentLabeler does not work in for loop

I am trying to get a set of binary images' eccentricity and solidity values using the regionprops function. I obtain the label matrix using the vision.ConnectedComponentLabeler function.
This is the code I have so far:
files = getFiles('images');
ecc = zeros(length(files)); %eccentricity values
sol = zeros(length(files)); %solidity values
ccl = vision.ConnectedComponentLabeler;
for i=1:length(files)
I = imread(files{i});
[L NUM] = step(ccl, I);
for j=1:NUM
L = changem(L==j, 1, j); %*
end
stats = regionprops(L, 'all');
ecc(i) = stats.Eccentricity;
sol(i) = stats.Solidity;
end
However, when I run this, I get an error says indicating the line marked with *:
Error using ConnectedComponentLabeler/step
Variable-size input signals are not supported when the OutputDataType property is set to 'Automatic'.'
I do not understand what MATLAB is talking about and I do not have any idea about how to get rid of it.
Edit
I have returned back to bwlabel function and have no problems now.
The error is a bit hard to understand, but I can explain what exactly it means. When you use the CVST Connected Components Labeller, it assumes that all of your images that you're going to use with the function are all the same size. That error happens because it looks like the images aren't... hence the notion about "Variable-size input signals".
The "Automatic" property means that the output data type of the images are automatic, meaning that you don't have to worry about whether the data type of the output is uint8, uint16, etc. If you want to remove this error, you need to manually set the output data type of the images produced by this labeller, or the OutputDataType property to be static. Hopefully, the images in the directory you're reading are all the same data type, so override this field to be a data type that this function accepts. The available types are uint8, uint16 and uint32. Therefore, assuming your images were uint8 for example, do this before you run your loop:
ccl = vision.ConnectedComponentLabeler;
ccl.OutputDataType = 'uint8';
Now run your code, and it should work. Bear in mind that the input needs to be logical for this to have any meaningful output.
Minor comment
Why are you using the CVST Connected Component Labeller when the Image Processing Toolbox bwlabel function works exactly the same way? As you are using regionprops, you have access to the Image Processing Toolbox, so this should be available to you. It's much simpler to use and requires no setup: http://www.mathworks.com/help/images/ref/bwlabel.html

term does not evaluate to a function taking 1 arguments

Please have a look at the following OpenCV code
Mat *curent;
current = new Mat();
cv::Rect bRect = cv::boundingRect(Mat(*points).reshape(2));
Mat roi = *current(bRect);
Here, I am trying to get a ROI to the Mat called roi. But whenever I try to get execute the last line of the above code I get the error term does not evaluate to a function taking 1 arguments. I have followed the same technique of getting an ROI without pointers number of times before in C++ and they worked. I guess the issue is with pointer current ? current must be a pointer because local variable slowed the application in an unbelievable way.
So, how can I solve this issue and get the ROI ?
please, throw out those pointers!
you're going to wreck havoc on the internal Mat refcounts, produce undefined behaviour and memleaks
"local variable slowed the application in an unbelievable way."
really, you think, copying a 58 byte struct is the reason ? i just don't believe you.
well i'll give you a hint, anyway - the ( ) operator has a higher precedence than the * operator.

MATLAB - image huffman encoding

I have a homework in which i have to convert some images to grayscale and compress them using huffman encoding. I converted them to grayscale and then i tried to compress them but i get an error. I used the code i found here.
Here is the code i'm using:
A=imread('Gray\36.png');
[symbols,p]=hist(A,unique(A))
p=p/sum(p)
[dict,avglen]=huffmandict(symbols,p)
comp=huffmanenco(A,dict)
This is the error i get. It occurs at the second line.
Error using eps
Class must be 'single' or 'double'.
Error in hist (line 90)
bins = xx + eps(xx);
What am i doing wrong?
Thanks.
P.S. how can i find the compression ratio for each image?
The problem is that when you specify the bin locations (the second input argument of 'hist'), they need to be single or double. The vector A itself does not, though. That's nice because sometimes you don't want to convert your whole dataset from an integer type to floating precision. This will fix your code:
[symbols,p]=hist(A,double(unique(A)))
Click here to see this issue is discussed more in detail.
first, try :
whos A
Seems like its type must be single or double. If not, just do A = double(A) after the imread line. Should work that way, however I'm surprised hist is not doing the conversion...
[EDIT] I have just tested it, and I am right, hist won't work in uint8, but it's okay as soon as I convert my image to double.

Is there histo function in MATLAB?

histo function in MATLAB, does anyone knows what it does? histo(image) what does this return?
I found in google but there I couldnt find any predefined function in MATLAB. Is there some new includes in Latest MATLAB. If anyone knows please explain what is happening below.
hist=histo(image);
pdf=hist/sum(hist);
t_new=round(sum(pdf.*[0:255]));
histo() is probably a user-defined function that counts image historgram. You can use built-in Matlab function hist() instead:
n = hist(image)
Read more:
http://en.wikipedia.org/wiki/Histogram
http://en.wikipedia.org/wiki/Histogram_equalization
The MATLAB command for calculating image histogram is imhist
It is used as
hist = imhist(image);

Resources