Add pixel index check to cntmap function (bug #1238)