-2

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.

Sam
  • 457
  • 1
  • 7
  • 15
  • I have never tried it, but I am 99% sure that the solution is: `cv.adaptiveThreshold(img,'MaxValue',255,'Method',mean,'Type',binary,'BlockSize ',3,'C',2);` . I mean, why did you specify just *some* of the option names? – Ander Biguri Aug 05 '16 at 08:16
  • @AnderBiguri, Thanks. My bad. I have forgot to do that. But still there is problem with the binary. th= cv.adaptiveThreshold(img,255,'Method',mean(img,1),'Type',binary,'BlockSize ',5,'C',5); Undefined function or variable 'binary'. Do you have any idea? I have the function in my mathlab path. – Sam Aug 05 '16 at 11:01
  • try `'Binary'` instead of `binary` . No offense, but you may need to learn some basic programming/types. – Ander Biguri Aug 05 '16 at 11:03
  • No change ! still the same problem. – Sam Aug 05 '16 at 11:04
  • Note that I havent changed the uppercase, but the `' '` around the word. Additionally, the default method is binary, so you can skip giving it to the function – Ander Biguri Aug 05 '16 at 11:04
  • yap. I did it but still. Error using adaptiveThreshold. Wrong number of arguments – Sam Aug 05 '16 at 11:06
  • BUT THAT'S A DIFFERENT ERROR. Please you are not really looking and what you are doing, just randomly copypasting code. After giving the image `img`, the rest of the arguments need to be pairs, `...,'NameOfArgument`,Value,...` . Are you giving `'MaxValule'`? – Ander Biguri Aug 05 '16 at 11:08
  • * __Type__ Thresholding type, default 'Binary'. One of: % * __Binary__ `dst(x,y) = (src(x,y) > thresh) ? maxValue : 0`. This is in the cv.adaptiveThreshold function. Do I have to add some extra variables? – Sam Aug 05 '16 at 11:10
  • This is my code, after all: th=cv.adaptiveThreshold(img,'MaxValue',255,'Method','Mean','Type','Binary','BlockSize ',3,'C',2); this error pops up: Unrecognized option BlockSize – Sam Aug 05 '16 at 11:17
  • Try to copy paste my answer. Note: you have a space after `BlockSize` – Ander Biguri Aug 05 '16 at 11:20
  • SO stupid of me, I have a scattered mind. Thanks for the help. It works now. – Sam Aug 05 '16 at 11:22

1 Answers1

1

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

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120