# help me to solve error in integer coding

2 views (last 30 days)
izyan hanum on 25 Apr 2015
Commented: Geoff Hayes on 25 Apr 2015
i dont know why have error in this coding. please help me to solve it
Error using ./ Integers can only be combined with integers of the same class, or scalar doubles.
Error in try1 (line 21) imgN=double(img-min(img(:)))/(max(img(:)-min(img(:))));
%# normalize to 0...1
imgN = double(img-min(img(:)))/(max(img(:)-min(img(:))));
th1=graythresh(imgN);
th2 = graythresh(imgN(imgN>th1));
cellMsk = imgN>th1;
nucMsk = imgN>th2;
figure,imshow(cellMsk+nucMsk,[])

Geoff Hayes on 25 Apr 2015
izayn - the problem in the line
imgN = double(img-min(img(:)))/(max(img(:)-min(img(:))));
is that the
double(img-min(img(:)))
is a multi-dimensional array (the same size as your matrix) and is of class/type double. The
(max(img(:)-min(img(:))))
will be a scalar of class/type that is the same as your image. I get the same error if I read an image where each element is a 8-bit unsigned integer. To get around this problem, just cast the right half of the equation to be of double type too. Your equation then becomes
imgN = double(img-min(img(:)))/double(max(img(:)-min(img(:))));
Try the above and see what happens!

izyan hanum on 25 Apr 2015
please run this code and there are error at filtImg = conv2(imgN,gf,'same');
%# normalize to 0...1
% imgN = double(img-min(img(:)))/(max(img(:)-min(img(:))));
imgN = double(img-min(img(:)))/double(max(img(:)-min(img(:))));
th1=graythresh(imgN);
th2 = graythresh(imgN(imgN>th1));
cellMsk = imgN>th1;
nucMsk = imgN>th2;
figure,imshow(cellMsk+nucMsk,[])
% (2) Smooth the raw image (to avoid over-segmentation) and impose nuclei as minima
[xx,yy]=ndgrid(-5:5,-5:5);
gf = exp((-xx.^2-yy.^2)/20);
filtImg = conv2(imgN,gf,'same');
figure,imshow(filtImg,[])
filtImgM = imimposemin(-filtImg,nucMsk);
% (3) Watershed, mask cells, and display
ws = watershed(filtImgM);
ws(~cellMsk) = 0;
lblImg = bwlabel(ws);
figure,imshow(label2rgb(lblImg,'jet','k','shuffle'));
izyan hanum on 25 Apr 2015
picture below
Geoff Hayes on 25 Apr 2015
izayn - if you are observing an error, please post it.