/** * Creates Gaussian derivative kernels. * * @param sigmas DOCUMENT ME! */ private void makeKernels2D(float[] sigmas) { int xkDim, ykDim; int[] derivOrder = new int[2]; kExtents = new int[2]; derivOrder[0] = 2; derivOrder[1] = 0; xkDim = Math.round(8 * sigmas[0]); if ((xkDim % 2) == 0) { xkDim++; } if (xkDim < 3) { xkDim = 3; } kExtents[0] = xkDim; ykDim = Math.round(8 * sigmas[1]); if ((ykDim % 2) == 0) { ykDim++; } if (ykDim < 3) { ykDim = 3; } kExtents[1] = ykDim; GxxData = new float[xkDim * ykDim]; GenerateGaussian Gxx = new GenerateGaussian(GxxData, kExtents, sigmas, derivOrder); Gxx.calc(false); derivOrder[0] = 0; derivOrder[1] = 2; GyyData = new float[xkDim * ykDim]; GenerateGaussian Gyy = new GenerateGaussian(GyyData, kExtents, sigmas, derivOrder); Gyy.calc(false); float tmp; for (int i = 0; i < GyyData.length; i++) { tmp = -(GxxData[i] + GyyData[i]); if (tmp > 0) { tmp *= amplificationFactor; } GxxData[i] = tmp; } }
/** Creates Gaussian derivative kernels. */ private void makeKernels2D() { int xkDim, ykDim; int[] derivOrder = new int[2]; kExtents = new int[2]; derivOrder[0] = 2; derivOrder[1] = 0; xkDim = Math.round(8 * sigmas[0]); if ((xkDim % 2) == 0) { xkDim++; } if (xkDim < 3) { xkDim = 3; } kExtents[0] = xkDim; ykDim = Math.round(8 * sigmas[1]); if ((ykDim % 2) == 0) { ykDim++; } if (ykDim < 3) { ykDim = 3; } kExtents[1] = ykDim; GxxData = new float[xkDim * ykDim]; GenerateGaussian Gxx = new GenerateGaussian(GxxData, kExtents, sigmas, derivOrder); Gxx.calc(false); Gxx.finalize(); Gxx = null; derivOrder[0] = 0; derivOrder[1] = 2; GyyData = new float[xkDim * ykDim]; GenerateGaussian Gyy = new GenerateGaussian(GyyData, kExtents, sigmas, derivOrder); Gyy.calc(false); Gyy.finalize(); Gyy = null; }
/** * This is a callback to be executed before resampleSingle is executed. The bilinear interpolation * coefficients are computed here and vary with the single, active slice. The offset into the * intermediate image is also computed since this also varies with the active slice. If encoding * of transparent data has occurred in the renderer constructor, then the current slice of the * encoding table is initialized for use by resampleSingle. */ protected void beforeResampleSingle() { // compute the 0-direction index ranges and weighting factors float fMin = (m_afShear[0] * m_iSlice) + m_afOffset[0]; m_afA[0] = fMin - (float) Math.floor(fMin); m_afB[0] = 1.0f - m_afA[0]; int iMin0 = (int) Math.ceil(fMin); // compute the 0-direction index ranges and weighting factors fMin = (m_afShear[1] * m_iSlice) + m_afOffset[1]; m_afA[1] = fMin - (float) Math.floor(fMin); m_afB[1] = 1.0f - m_afA[1]; int iMin1 = (int) Math.ceil(fMin); // offset into intermediate image of rendered voxel data m_iInterOffset = iMin0 + (m_iInterBound * iMin1); if (m_bDoEncodeSkip) { m_aasSliceEncode = m_aaasVolumeEncode[m_iSlice]; } }
/** * The top level rendering call. This function calls beforeResampleAll, resampleAll, and * mapIntermediateToFinal, all virtual functions that are implemented in derived classes. * * @param iDS The number of slices to increment during the resampling phase. The value should be * one or larger. If one, all slices of the volume data are resampled. If two, only every * other slice is resampled. An input larger than one is used to allow fast rendering during * rotation of the volume data. Once the rotation terminates, a composite with input of one * should be called. */ public synchronized void composite(int iDS) { long startTime = 0, now = 0; double elapsedTime = 0d; // compute maximum component of the box direction vector float fMax = 0.0f; int i, iMax = -1; for (i = 0; i < 3; i++) { float fAbs = Math.abs(m_aafBox[2][i]); if (fAbs > fMax) { fMax = fAbs; iMax = i; } } startTime = System.currentTimeMillis(); traceInit(); // composite in the appropriate direction if (iMax == 0) { beforeResampleAll(1, 2, 0); } else if (iMax == 1) { beforeResampleAll(2, 0, 1); } else { beforeResampleAll(0, 1, 2); } resampleAll(iDS); mapIntermediateToFinal(); now = System.currentTimeMillis(); elapsedTime = (double) (now - startTime); if (elapsedTime <= 0) { elapsedTime = (double) 0.0; } Preferences.debug( "Shear elapse time = " + (double) (elapsedTime / 1000.0) + "\n"); // in seconds }
/** * Rotate the oriented bounding box of the 3D image about the specified axis with the specified * angle. * * @param transform The transform and its matrix by which to rotate the image. */ public void rotateFrameBy(Transform3D transform) { double rY, rX, rZ; double sinrX, sinrY, sinrZ, cosrX, cosrY, cosrZ; Matrix3d matrix = new Matrix3d(); transform.get(matrix); rY = -Math.asin(matrix.m02); if (Math.cos(rY) != 0) { rX = -Math.atan2(matrix.m12, matrix.m22); rZ = Math.atan2(matrix.m01, matrix.m00); } else { rX = -Math.atan2(matrix.m10, matrix.m11); rZ = 0; } cosrX = Math.cos(rX); sinrX = Math.sin(rX); cosrY = Math.cos(rY); sinrY = Math.sin(rY); cosrZ = Math.cos(rZ); sinrZ = Math.sin(rZ); matrix.m00 = cosrZ * cosrY; matrix.m01 = -sinrZ * cosrY; matrix.m02 = sinrY; matrix.m10 = (cosrZ * sinrY * sinrX) + (sinrZ * cosrX); matrix.m11 = (-sinrZ * sinrY * sinrX) + (cosrZ * cosrX); matrix.m12 = -cosrY * sinrX; matrix.m20 = (-cosrZ * sinrY * cosrX) + (sinrZ * sinrX); matrix.m21 = (sinrZ * sinrY * cosrX) + (cosrZ * sinrX); matrix.m22 = cosrY * cosrX; m_kRotate.set(matrix); m_akAxis[0] = new Vector3f(1.0f, 0.0f, 0.0f); m_akAxis[1] = new Vector3f(0.0f, 1.0f, 0.0f); m_akAxis[2] = new Vector3f(0.0f, 0.0f, 1.0f); for (int i = 0; i < 3; i++) { m_kRotate.transform(m_akAxis[i]); } orthonormalize(m_akAxis); for (int i = 0; i < 3; i++) { setAxis(i, m_akAxis[i]); } }
/** * This function produces the EdgeLap of input image. * * @param detectionType the type of zero crossing detection to perform */ private void calcStoreInDest3D(int detectionType) { int nImages; int length, totalLength; float[] buffer, xResultBuffer, yResultBuffer, zResultBuffer; int start; float[] sliceBuffer; try { destImage.setLock(); } catch (IOException error) { errorCleanUp("Algorithm EdgeLapSep: Image(s) locked", false); return; } try { length = srcImage.getSliceSize(); totalLength = srcImage.getSliceSize() * srcImage.getExtents()[2]; nImages = srcImage.getExtents()[2]; buffer = new float[totalLength]; sliceBuffer = new float[length]; srcImage.exportData(0, totalLength, buffer); // locks and releases lock // fireProgressStateChanged(srcImage.getImageName(), "Calculating Zero X-ings ..."); } catch (IOException error) { buffer = null; sliceBuffer = null; xResultBuffer = null; yResultBuffer = null; zResultBuffer = null; errorCleanUp("Algorithm EdgeLapSep exportData: Image(s) locked", true); return; } catch (OutOfMemoryError e) { buffer = null; sliceBuffer = null; xResultBuffer = null; yResultBuffer = null; zResultBuffer = null; errorCleanUp("Algorithm EdgeLapSep: Out of memory", true); return; } // initProgressBar(); fireProgressStateChanged(0, srcImage.getImageName(), "Convolving X dimension ..."); /** Minimum and maximum progress value for the convolving part */ int min = 0; int max = min + Math.round(100 / 2.0f); float stepPerDimension = ((float) (max - min)) / 3.0f; AlgorithmSeparableConvolver xConvolver = null; if (Math.round(stepPerDimension) > 1) { xConvolver = new AlgorithmSeparableConvolver( buffer, srcImage.getExtents(), GxxData, kExtents, false); // assume not color xConvolver.setProgressValues(generateProgressValues(min, min + Math.round(stepPerDimension))); linkProgressToAlgorithm(xConvolver); } else { xConvolver = new AlgorithmSeparableConvolver( buffer, srcImage.getExtents(), GxxData, kExtents, false); // assume not color } if (!entireImage) { xConvolver.setMask(mask); } xConvolver.run(); xResultBuffer = xConvolver.getOutputBuffer(); xConvolver.finalize(); xConvolver = null; fireProgressStateChanged( min + Math.round(stepPerDimension), srcImage.getImageName(), "Convolving Y dimension..."); AlgorithmSeparableConvolver yConvolver = null; if ((Math.round(stepPerDimension * 2) - Math.round(stepPerDimension)) > 1) { yConvolver = new AlgorithmSeparableConvolver( buffer, srcImage.getExtents(), GyyData, kExtents, false); // assume not color yConvolver.setProgressValues( generateProgressValues( min + Math.round(stepPerDimension), min + Math.round(stepPerDimension * 2))); linkProgressToAlgorithm(yConvolver); } else { yConvolver = new AlgorithmSeparableConvolver( buffer, srcImage.getExtents(), GyyData, kExtents, false); // assume not color } if (!entireImage) { yConvolver.setMask(mask); } yConvolver.run(); yResultBuffer = yConvolver.getOutputBuffer(); yConvolver.finalize(); yConvolver = null; fireProgressStateChanged( min + Math.round(stepPerDimension * 2), srcImage.getImageName(), "Convolving Z dimension..."); AlgorithmSeparableConvolver zConvolver = null; if ((Math.round(stepPerDimension * 3) - Math.round(stepPerDimension * 2)) > 1) { zConvolver = new AlgorithmSeparableConvolver( buffer, srcImage.getExtents(), GzzData, kExtents, false); // assume not color zConvolver.setProgressValues( generateProgressValues(min + Math.round(stepPerDimension * 2), max)); linkProgressToAlgorithm(zConvolver); } else { zConvolver = new AlgorithmSeparableConvolver( buffer, srcImage.getExtents(), GzzData, kExtents, false); // assume not color } if (!entireImage) { zConvolver.setMask(mask); } zConvolver.run(); zResultBuffer = zConvolver.getOutputBuffer(); zConvolver.finalize(); zConvolver = null; min = max; max = 100; float stepPerImage = ((float) (max - min)) / nImages; for (int s = 0; (s < nImages) && !threadStopped; s++) { fireProgressStateChanged( min + Math.round(stepPerImage * s), srcImage.getImageName(), "Calculating the edges of slice " + (s + 1) + "..."); start = s * length; for (int i = start; (i < (start + length)) && !threadStopped; i++) { if (entireImage || mask.get(i)) { destImage.set(i, -(xResultBuffer[i] + yResultBuffer[i] + zResultBuffer[i])); } else { destImage.set(i, buffer[i]); } } try { destImage.exportDataNoLock(start, length, sliceBuffer); } catch (IOException error) { buffer = null; sliceBuffer = null; errorCleanUp("Algorithm EdgeLapSep exportData: " + error, true); return; } genZeroXMask(s, sliceBuffer, detectionType); } if (threadStopped) { finalize(); return; } zXMask.calcMinMax(); destImage.calcMinMax(); destImage.releaseLock(); setCompleted(true); }
/** * This function produces the EdgeLap of input image. * * @param nImages number of images on which to find zero crossings. If 2D image then nImage = 1. * If 3D image where each image is to processed independently then nImages equals the number * of images in the volume. * @param detectionType the type of zero crossing detection to perform */ private void calcStoreInDest2D(int nImages, int detectionType) { // int i, s, idx; int length; int start; float[] buffer, xResultBuffer, yResultBuffer; try { destImage.setLock(); } catch (IOException error) { errorCleanUp("Algorithm EdgeLapSep: Image(s) locked", false); return; } try { length = srcImage.getSliceSize(); buffer = new float[length]; // fireProgressStateChanged(srcImage.getImageName(), "Calculating the Edge ..."); } catch (OutOfMemoryError e) { buffer = null; errorCleanUp("Algorithm Edge Lap Sep: Out of memory", true); return; } fireProgressStateChanged(0, srcImage.getImageName(), "Calculating the Edge ..."); float stepPerImage = 100f / nImages; // initProgressBar(); for (int s = 0; (s < nImages) && !threadStopped; s++) { fireProgressStateChanged( Math.round(stepPerImage * s), srcImage.getImageName(), "Calculating the edges of slice " + (s + 1) + "..."); start = s * length; try { srcImage.exportData(start, length, buffer); // locks and releases lock } catch (IOException error) { errorCleanUp("Algorithm EdgeLapSep: Image(s) locked", false); return; } int min = Math.round(stepPerImage * s); int max = min + Math.round(((float) (Math.round(stepPerImage * (s + 1)) - min)) / 2.0f); AlgorithmSeparableConvolver xConvolver = null; if ((max - min) > 1) { xConvolver = new AlgorithmSeparableConvolver( buffer, new int[] {srcImage.getExtents()[0], srcImage.getExtents()[1]}, GxxData, kExtents, false); xConvolver.setProgressValues(generateProgressValues(min, max)); linkProgressToAlgorithm(xConvolver); } else { xConvolver = new AlgorithmSeparableConvolver( buffer, new int[] {srcImage.getExtents()[0], srcImage.getExtents()[1]}, GxxData, kExtents, false); // assume not color } if (!entireImage) { xConvolver.setMask(mask); } xConvolver.run(); xResultBuffer = xConvolver.getOutputBuffer(); xConvolver.finalize(); xConvolver = null; min = max; max = Math.round(stepPerImage * (s + 1)); AlgorithmSeparableConvolver yConvolver = null; if ((max - min) > 1) { yConvolver = new AlgorithmSeparableConvolver( buffer, new int[] {srcImage.getExtents()[0], srcImage.getExtents()[1]}, GyyData, kExtents, false); yConvolver.setProgressValues(generateProgressValues(min, max)); linkProgressToAlgorithm(yConvolver); } else { yConvolver = new AlgorithmSeparableConvolver( buffer, new int[] {srcImage.getExtents()[0], srcImage.getExtents()[1]}, GyyData, kExtents, false); // assume not color } if (!entireImage) { yConvolver.setMask(mask); } yConvolver.run(); yResultBuffer = yConvolver.getOutputBuffer(); yConvolver.finalize(); yConvolver = null; for (int i = 0, idx = start; (i < buffer.length) && !threadStopped; i++, idx++) { if (entireImage || mask.get(i)) { destImage.set(idx, -(xResultBuffer[i] + yResultBuffer[i])); } else { destImage.set(idx, buffer[i]); } } try { destImage.exportDataNoLock(start, length, buffer); } catch (IOException error) { errorCleanUp("Algorithm EdgeLapSep exportData: " + error, false); return; } genZeroXMask(s, buffer, detectionType); } if (threadStopped) { finalize(); return; } zXMask.calcMinMax(); destImage.calcMinMax(); destImage.releaseLock(); setCompleted(true); }
/** cat. */ private void cat3D_4D_4D() { int length; int xDim, yDim; float[] buffer; int cFactor = 1; int i, j; float[] resols = new float[3]; float[] origins = new float[3]; FileInfoBase[] fileInfo = null; FileInfoDicom[] fileInfoDicom = null; int srcALength, srcBLength; try { fireProgressStateChanged(srcImage1.getImageName(), "Concatenating images ..."); resols = new float[4]; origins = new float[4]; xDim = srcImage1.getExtents()[0]; yDim = srcImage1.getExtents()[1]; if (srcImage1.isColorImage()) { cFactor = 4; } length = cFactor * xDim * yDim; buffer = new float[length]; int nImages; if (srcImage1.getNDims() > srcImage2.getNDims()) { nImages = (srcImage1.getExtents()[2] * srcImage1.getExtents()[3]) + srcImage2.getExtents()[2]; for (i = 0; (i < (srcImage1.getExtents()[2] * srcImage1.getExtents()[3])) && !threadStopped; i++) { fireProgressStateChanged(Math.round((float) (i) / (nImages - 1) * 100)); srcImage1.exportData(i * length, length, buffer); destImage.importData(i * length, buffer, false); } if (threadStopped) { buffer = null; finalize(); return; } for (j = 0; (j < srcImage2.getExtents()[2]) && !threadStopped; j++) { fireProgressStateChanged(Math.round((float) (i + j) / (nImages - 1) * 100)); srcImage2.exportData(j * length, length, buffer); destImage.importData((i + j) * length, buffer, false); } if (threadStopped) { buffer = null; finalize(); return; } destImage.calcMinMax(); } else { nImages = (srcImage2.getExtents()[2] * srcImage2.getExtents()[3]) + srcImage1.getExtents()[2]; for (j = 0; (j < srcImage1.getExtents()[2]) && !threadStopped; j++) { fireProgressStateChanged(Math.round((float) (j) / (nImages - 1) * 100)); srcImage1.exportData(j * length, length, buffer); destImage.importData(j * length, buffer, false); } if (threadStopped) { buffer = null; finalize(); return; } for (i = 0; (i < (srcImage2.getExtents()[2] * srcImage2.getExtents()[3])) && !threadStopped; i++) { fireProgressStateChanged(Math.round((float) (i + j) / (nImages - 1) * 100)); srcImage2.exportData(i * buffer.length, length, buffer); destImage.importData((i + j) * buffer.length, buffer, false); } if (threadStopped) { buffer = null; finalize(); return; } destImage.calcMinMax(); } } catch (IOException error) { buffer = null; destImage.disposeLocal(); // Clean up memory of result image destImage = null; errorCleanUp("Algorithm Concat. Images: Image(s) locked", true); return; } catch (OutOfMemoryError e) { buffer = null; destImage.disposeLocal(); // Clean up memory of result image destImage = null; errorCleanUp("Algorithm Concat. Images: Out of memory", true); return; } resols[0] = srcImage1.getFileInfo()[0].getResolutions()[0]; resols[1] = srcImage1.getFileInfo()[0].getResolutions()[1]; resols[2] = srcImage1.getFileInfo()[0].getResolutions()[2]; resols[3] = srcImage1.getFileInfo()[0].getResolutions()[3]; origins[0] = srcImage1.getFileInfo()[0].getOrigin()[0]; origins[1] = srcImage1.getFileInfo()[0].getOrigin()[1]; origins[2] = srcImage1.getFileInfo()[0].getOrigin()[2]; origins[3] = srcImage1.getFileInfo()[0].getOrigin()[3]; if ((srcImage1.getFileInfo()[0] instanceof FileInfoDicom) && (srcImage2.getFileInfo()[0] instanceof FileInfoDicom)) { fileInfoDicom = new FileInfoDicom[destImage.getExtents()[2] * destImage.getExtents()[3]]; if (srcImage1.getNDims() > srcImage2.getNDims()) { srcALength = srcImage1.getExtents()[2] * srcImage1.getExtents()[3]; for (i = 0; (i < srcALength) && !threadStopped; i++) { fileInfoDicom[i] = (FileInfoDicom) (((FileInfoDicom) srcImage1.getFileInfo()[i]).clone()); fileInfoDicom[i].setOrigin(origins); } for (i = 0; (i < srcImage2.getExtents()[2]) && !threadStopped; i++) { fileInfoDicom[srcALength + i] = (FileInfoDicom) (((FileInfoDicom) srcImage2.getFileInfo()[i]).clone()); fileInfoDicom[srcALength + i].setOrigin(origins); } } else { srcBLength = srcImage2.getExtents()[2] * srcImage2.getExtents()[3]; for (i = 0; (i < srcImage1.getExtents()[2]) && !threadStopped; i++) { fileInfoDicom[i] = (FileInfoDicom) (((FileInfoDicom) srcImage1.getFileInfo()[i]).clone()); fileInfoDicom[i].setOrigin(origins); } for (i = 0; (i < srcBLength) && !threadStopped; i++) { fileInfoDicom[srcImage1.getExtents()[2] + i] = (FileInfoDicom) (((FileInfoDicom) srcImage2.getFileInfo()[i]).clone()); fileInfoDicom[srcImage1.getExtents()[2] + i].setOrigin(origins); } } destImage.setFileInfo(fileInfoDicom); } else { fileInfo = destImage.getFileInfo(); for (i = 0; (i < (destImage.getExtents()[2] * destImage.getExtents()[3])) && !threadStopped; i++) { fileInfo[i].setModality(srcImage1.getFileInfo()[0].getModality()); fileInfo[i].setFileDirectory(srcImage1.getFileInfo()[0].getFileDirectory()); fileInfo[i].setEndianess(srcImage1.getFileInfo()[0].getEndianess()); fileInfo[i].setUnitsOfMeasure(srcImage1.getFileInfo()[0].getUnitsOfMeasure()); fileInfo[i].setResolutions(resols); fileInfo[i].setExtents(destImage.getExtents()); fileInfo[i].setMax(destImage.getMax()); fileInfo[i].setMin(destImage.getMin()); fileInfo[i].setImageOrientation(srcImage1.getImageOrientation()); fileInfo[i].setPixelPadValue(srcImage1.getFileInfo()[0].getPixelPadValue()); fileInfo[i].setPhotometric(srcImage1.getFileInfo()[0].getPhotometric()); fileInfo[i].setAxisOrientation(srcImage1.getAxisOrientation()); } if (srcImage1.getFileInfo()[0] instanceof FileInfoImageXML) { if (srcImage1.getNDims() > srcImage2.getNDims()) { srcALength = srcImage1.getExtents()[2] * srcImage1.getExtents()[3]; for (i = 0; (i < srcALength) && !threadStopped; i++) { if (((FileInfoImageXML) srcImage1.getFileInfo()[i]).getPSetHashtable() != null) { ((FileInfoImageXML) fileInfo[i]) .setPSetHashtable( ((FileInfoImageXML) srcImage1.getFileInfo()[i]).getPSetHashtable()); } } } else { for (i = 0; (i < srcImage1.getExtents()[2]) && !threadStopped; i++) { if (((FileInfoImageXML) srcImage1.getFileInfo()[i]).getPSetHashtable() != null) { ((FileInfoImageXML) fileInfo[i]) .setPSetHashtable( ((FileInfoImageXML) srcImage1.getFileInfo()[i]).getPSetHashtable()); } } } } if (srcImage2.getFileInfo()[0] instanceof FileInfoImageXML) { if (srcImage1.getNDims() > srcImage2.getNDims()) { srcALength = srcImage1.getExtents()[2] * srcImage1.getExtents()[3]; for (i = 0; (i < srcImage2.getExtents()[2]) && !threadStopped; i++) { if (((FileInfoImageXML) srcImage2.getFileInfo()[i]).getPSetHashtable() != null) { ((FileInfoImageXML) fileInfo[srcALength + i]) .setPSetHashtable( ((FileInfoImageXML) srcImage2.getFileInfo()[i]).getPSetHashtable()); } } } else { srcBLength = srcImage2.getExtents()[2] * srcImage2.getExtents()[3]; for (i = 0; (i < srcBLength) && !threadStopped; i++) { if (((FileInfoImageXML) srcImage2.getFileInfo()[i]).getPSetHashtable() != null) { ((FileInfoImageXML) fileInfo[srcImage1.getExtents()[2] + i]) .setPSetHashtable( ((FileInfoImageXML) srcImage2.getFileInfo()[i]).getPSetHashtable()); } } } } } if (threadStopped) { buffer = null; finalize(); return; } setCompleted(true); fileInfo = null; fileInfoDicom = null; }
/** This function produces the Laplacian of input image. */ private void calcStoreInDest3D() { int i; int length; float[] buffer; float lap; try { destImage.setLock(); } catch (IOException error) { displayError("Algorithm Laplacian: Image(s) locked"); setCompleted(false); destImage.releaseLock(); return; } try { length = srcImage.getSliceSize() * srcImage.getExtents()[2]; buffer = new float[length]; srcImage.exportData(0, length, buffer); // locks and releases lock fireProgressStateChanged(srcImage.getImageName(), "Calculating the Laplacian ..."); } catch (IOException error) { buffer = null; errorCleanUp("Algorithm Laplacian exportData: Image(s) locked", true); return; } catch (OutOfMemoryError e) { buffer = null; errorCleanUp("Algorithm Laplacian exportData: Out of memory", true); return; } int mod = length / 100; // mod is 1 percent of length float min, max; min = Float.MAX_VALUE; max = -Float.MAX_VALUE; float minL, maxL; minL = Float.MAX_VALUE; maxL = -Float.MAX_VALUE; if (entireImage == false) { for (i = 0; i < length; i++) { if (mask.get(i)) { if (buffer[i] > max) { max = buffer[i]; } else if (buffer[i] < min) { min = buffer[i]; } } } } for (i = 0; (i < length) && !threadStopped; i++) { if (((i % mod) == 0)) { fireProgressStateChanged(Math.round((float) i / (length - 1) * 100)); } if ((entireImage == true) || mask.get(i)) { lap = AlgorithmConvolver.convolve3DPt(i, srcImage.getExtents(), buffer, kExtents, GxxData); if (entireImage == false) { if (mask.get(i)) { if (lap > maxL) { maxL = lap; } else if (lap < minL) { minL = lap; } } } destImage.set(i, lap); } else { destImage.set(i, buffer[i]); } } if (entireImage == false) { for (i = 0; i < length; i++) { if (mask.get(i)) { lap = destImage.getFloat(i); lap = (((lap - minL) / (maxL - minL)) * (max - min)) + min; destImage.set(i, lap); } } } if (threadStopped) { finalize(); return; } destImage.calcMinMax(); destImage.releaseLock(); setCompleted(true); }
/** * This function produces the Laplacian of input image. See this Neva * * @param nImages number of images to be blurred. If 2D image then nImage = 1, if 3D image where * each image is to processed independently then nImages equals the number of images in the * volume. */ private void calcStoreInDest2D(int nImages) { int i, s; int length; float[] buffer; float[] resultBuffer; float lap; try { length = srcImage.getSliceSize(); buffer = new float[length]; resultBuffer = new float[length]; fireProgressStateChanged(srcImage.getImageName(), "Calculating the Laplacian ..."); } catch (OutOfMemoryError e) { buffer = null; resultBuffer = null; errorCleanUp("Algorithm Laplacian exportData: Out of memory", true); return; } try { srcImage.exportData(0, length, buffer); // locks and releases lock } catch (IOException error) { displayError("Algorithm Gaussian Blur: Image(s) locked"); setCompleted(false); destImage.releaseLock(); return; } float[] sigs = new float[2]; for (s = 1; (s <= 8) && !threadStopped; s++) { sigs[0] = s; sigs[1] = s; makeKernels2D(sigs); fireProgressStateChanged(Math.round((float) (s) / 8 * 100)); for (i = 0; (i < length) && !threadStopped; i++) { lap = AlgorithmConvolver.convolve2DPtMed(i, srcImage.getExtents(), buffer, kExtents, GxxData); if (lap > resultBuffer[i]) { resultBuffer[i] = lap; } } } if (threadStopped) { finalize(); return; } try { destImage.importData(0, resultBuffer, true); } catch (IOException error) { errorCleanUp("Algorithm Gaussian Blur: Image(s) locked", false); return; } setCompleted(true); }
/** * Calculates the Laplacian image and replaces the source image with the new image. * * @param buffer DOCUMENT ME! * @param extents DOCUMENT ME! * @return resultBuffer */ @SuppressWarnings("unused") private float[] calcInPlace3DBuffer(float[] buffer, int[] extents) { int i, s; int length; float[] resultBuffer; float lap; try { if (buffer == null) { length = srcImage.getSliceSize() * srcImage.getExtents()[2]; buffer = new float[length]; } else { length = buffer.length; } resultBuffer = new float[length]; sBuffer = new byte[length]; if (srcImage != null) { fireProgressStateChanged(srcImage.getImageName(), "Calculating the Laplacian ..."); } else { fireProgressStateChanged("Medialness", "Calculating the Laplacian ..."); } } catch (OutOfMemoryError e) { buffer = null; resultBuffer = null; sBuffer = null; errorCleanUp("Algorithm Laplacian exportData: Out of memory", true); return null; } try { if (srcImage != null) { srcImage.exportData(0, length, buffer); // locks and releases lock } } catch (IOException error) { buffer = null; resultBuffer = null; System.gc(); errorCleanUp("Algorithm Laplacian: " + error, false); return null; } float[] sigs = new float[3]; for (s = 1; (s <= 8) && !threadStopped; s++) { sigs[0] = s; sigs[1] = s; sigs[2] = s; makeKernels3D(sigs); fireProgressStateChanged(Math.round((float) (s) / 8 * 100)); for (i = 0; (i < length) && !threadStopped; i++) { // if (entireImage == true || mask.get(i)) { lap = AlgorithmConvolver.convolve3DPtMed(i, extents, buffer, kExtents, GxxData); if (lap > resultBuffer[i]) { resultBuffer[i] = lap; } sBuffer[i] = (byte) s; // } // else { // resultBuffer[i] = 0; // } } } return resultBuffer; }
/** Calculates the Laplacian and replaces the source image with the new image. */ private void calcInPlace3D() { int i; int length; float[] buffer; float[] resultBuffer; float lap; try { length = srcImage.getSliceSize() * srcImage.getExtents()[2]; buffer = new float[length]; resultBuffer = new float[length]; srcImage.exportData(0, length, buffer); // locks and releases lock fireProgressStateChanged(srcImage.getImageName(), "Calculating the Laplacian ..."); } catch (IOException error) { buffer = null; resultBuffer = null; errorCleanUp("Algorithm Laplacian exportData: Image(s) locked", true); return; } catch (OutOfMemoryError e) { errorCleanUp("Algorithm Laplacian exportData: Out of memory", true); return; } int mod = length / 100; // mod is 1 percent of length for (i = 0; (i < length) && !threadStopped; i++) { if (((i % mod) == 0)) { fireProgressStateChanged(Math.round((float) i / (length - 1) * 100)); } if ((entireImage == true) || mask.get(i)) { lap = AlgorithmConvolver.convolve3DPt(i, srcImage.getExtents(), buffer, kExtents, GxxData); resultBuffer[i] = lap; } else { resultBuffer[i] = buffer[i]; } } buffer = null; System.gc(); if (threadStopped) { finalize(); return; } try { srcImage.importData(0, resultBuffer, true); } catch (IOException error) { buffer = null; resultBuffer = null; errorCleanUp("Algorithm Laplacian importData: Image(s) locked", true); return; } setCompleted(true); }