I wanted to apply cv.adaptiveThreshold (opencv) through matlab on 8-bit single-channel uint8 image but I am always getting error. I have tried following code from this website: https://kyamagu.github.io/mexopencv/matlab/adaptiveThreshold.html
th = cv.adaptiveThreshold(img,255,'Method',mean,'Type',binary,3,2);
and it gives me the error of Not enough input argument.
when I am running like this:
th = cv.adaptiveThreshold(img);
it is working properly but this is not what I want. I don't want to apply default methods and criteria.
Thanks for the help.
Read the documentation. You are not following the function argument list
cv.adaptiveThreshold(img,'MaxValue',255,'Method','Mean','Type','Binary','BlockSize',3,'C',2);
should work
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'm applying some image processing techniques in MATLAB I was able to segment the license plate as show in the figure below:
Now if I apply the followig code in a for loop:
ocrResults = ocr(finalImage);
ocrResults.Text
I'm getting output like VV, u etc that means these characters are not recognized properly. So, how can I fix that? It's not mandatory to use the OCR class so any other solution will also work.
MATLAB's ocr function accepts additional inputs as Name/Value pairs. In your case, to limit the output to numeric values, simply add in the following parameters:
ocrResults = ocr( finalImage, 'CharacterSet', '0123456789' );
However, I'm not certain doing just this will get you the output you desire. It might be helpful to erode the image and add additional blackspace around each character. Take advantage of other possible input parameters which may be added, such as 'TextLayout'.
I am working on a project in Matlab and i have to use the gradient function. Following is my code snippet:
im=imread('A.jpg'); //Reads image File
[Ix,Iy]=gradient(rgb2gray(im));
I am Getting the Following error.
Error using bsxfun
Mixed integer class inputs are not supported.
Error in gradient (line 68)
g(2:n-1,:) = bsxfun(#rdivide,(f(3:n,:)-f(1:n-2,:)),h);
I am not able to understand why this error is showing up and how to resolve it.
PS: I know there are many questions posted related to same error but they are due to different causes. I have gone through them but am not to solve my problem.
load an image.
Use rgb2grey if necessary.
Use im2double
Use gradient function, i.e., [fx,fy]=gradient(image)
Use matlab function quiver(fx,fy) to get the result displayed.
Ahsan Latif
You should try [Ix, Iy] = gradient(double(rgb2gray(A))). Or alternatively, as Daniel suggests, use imgradient.
I'm trying to implement with the matlab function imhistmatch.
So I use following commends.
A= imread('example1.jpg')
B= imread('example2.jpg')
C= imhistmatch(A,B)
But there is problem like this.
?? Undefined functionor method 'imhistmatch' for input arguments of type 'uint8'
So What am I suppose to do for solve?
I am not sure about your question. Are you trying to implement imhistmatch?
Then probably your function is in the wrong folder or you have a typo in the functions name.
use
addpath('Pathto/imhistmatch')
to ensure that matlab can find your implemented function.
But maybe you want to use the function imhistmatch provided by the image processing toolbox. Then, I guess you don't have the image processing toolbox.
Try
ver
and check the output. You should find these lines:
MATLAB Version X.X (XXXXX)
Image Processing Toolbox Version X.X (XXXXX)
If not, then you may want to buy the image processing toolbox, get a evaluation version or maybe try octave.
On my computer the following works:
imhistmatch(ones(10),ones(10))
imhistmatch(ones(10,'uint8'),ones(10,'uint8'))
but when I type
imhistmatch(ones(10,'int8'),ones(10,'int8'))
I get an error:
Error using imhistmatch
Expected input number 1, A, to be one of these types:
uint8, uint16, double, int16, single
Instead its type was int8.
...
So, if it would be a type problem you would see another error.
Your error is the result of not having the proper function imhistmatch.
I'm using imfreehand in my program, and when I came to erosion, I got the following error (I didn't paste the whole error):
Error using imerode
Expected input number 1, IM, to be one of these types:
numeric, logical
Instead its type was imfreehand.
It seems then that the region I extract will be of type imfreehand? Is there a way to convert to the above data types? Or, there is some way to deal with such issue?
Thanks.
You can take a look at the examples in this post. My interpretation is that you create a mask using the handle associated with the generated freehand object,
hFH = imfreehand();
binaryImage = hFH.createMask();
then use the mask for additional purposes.