previousGrayImageDataList = []; function updateGrayCanvasDataOnMatcghedLocation(termList, maskCanvasData, coloreImageData, grayImageData, grayImageMRDataList, bodyRegionId, canvasId) { var n = maskCanvasData.data.length; var maskData = maskCanvasData.data; for (var z = 0; z < termList.length; z++) { if (previousGrayImageDataList[parseInt(bodyRegionId - 1)] != null) { grayImageData = previousGrayImageDataList[parseInt(bodyRegionId - 1)]; } var grayImageDataVar = grayImageData.data; var coloredImageDataVar = coloreImageData.data; for (var i = 0; i < n; i += 4) { var RED = maskData[i] - 9; var GREEN = maskData[i + 1] - 9; var BLUE = maskData[i + 2] - 9; var Red; var Green; var Blue; var zero = "0"; if ((RED).toString().length != 2) { Red = zero.concat((RED).toString()) } else { Red = (RED).toString() } if ((GREEN).toString().length != 2) { Green = zero.concat((GREEN).toString()) } else { Green = (GREEN).toString() } if ((BLUE).toString().length != 2) { Blue = zero.concat((BLUE).toString()) } else { Blue = (BLUE).toString() } var Icolor = (Red + Green + Blue); if (parseInt(termList[z]._TermNumber) == parseInt(Icolor)) { var RED_coloredImage = coloredImageDataVar[i]; grayImageDataVar[i] = RED_coloredImage; var GREEN_coloredImage = coloredImageDataVar[i + 1]; grayImageDataVar[i + 1] = GREEN_coloredImage; var BLUE_coloredImage = coloredImageDataVar[i + 2]; grayImageDataVar[i + 2] = BLUE_coloredImage; var ALPHA_coloredImage = coloredImageDataVar[i + 3]; grayImageDataVar[i + 3] = ALPHA_coloredImage; } } previousGrayImageDataList[parseInt(bodyRegionId - 1)] = grayImageData; } self.postMessage({ 'bodyRegionId': bodyRegionId, 'value': grayImageData, 'canvasId': canvasId }); } self.onmessage = function (e) { updateGrayCanvasDataOnMatcghedLocation(e.data.termList, e.data.maskCanvasData, e.data.coloreImageData, e.data.grayImageData, e.data.grayImageMRDataList, e.data.bodyRegionId, e.data.canvasId); }