Clear Filters
Clear Filters

Following is the error occured during thresholding

1 view (last 30 days)
Following is the error occured in my code. please, can you help me for sorting out this error.
Error using .* Integers can only be combined with integers of the same class, or scalar doubles.
Error in thresholding (line 13) thix1=max(ix,level1.*ones(size(ix)));

Accepted Answer

Image Analyst
Image Analyst on 23 Apr 2016
Try this:
hix1 = max(ix, uint8(level1).*ones(size(ix), 'uint8'));
or this:
hix1 = uint8(max(double(ix), level1.*ones(size(ix))));

More Answers (1)

Walter Roberson
Walter Roberson on 23 Apr 2016
Your datatype for your image, ix, is uint8 . Your level1 is a double. You cannot use max() to combine uint8 and double.
Suppose one of the entries was uint8(4) and level1 was double(7.283), then since double(7.283) is larger than uint8(4) then you would expect double(7.283) to be the result for that location. But for uint8(9) since that is greater than double(7.283) you would expect uint8(9) to be the result for there. You would thus be expecting double() to be the result at one place and uint8() to be the result at another place, but it is not possible to have uint8 and double in the same array.
You will need to convert your ix to double or you will need to convert your level1 to uint8
By the way, you can leave level1 as a scalar instead of using level1.*ones(size(ix))

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!