diff --git a/src/org/doube/bonej/pqct/Get_Vertical_Flip.java b/src/org/doube/bonej/pqct/Get_Vertical_Flip.java deleted file mode 100644 index 2e6c493b..00000000 --- a/src/org/doube/bonej/pqct/Get_Vertical_Flip.java +++ /dev/null @@ -1,509 +0,0 @@ -/* - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - - N.B. the above text was copied from http://www.gnu.org/licenses/gpl.html - unmodified. I have not attached a copy of the GNU license to the source... - - ImageJ density distribution analysis plugin - Copyright (C) 2011 Timo Rantalainen -*/ - -package org.doube.bonej.pqct; - -import ij.*; -import ij.text.*; -import ij.process.*; -import ij.gui.*; -import ij.measure.*; //Calibration -import java.util.*; //Vector -import java.io.*; //File IO for reading .TYP files -import ij.plugin.PlugIn; -import org.doube.bonej.pqct.analysis.*; //Analysis stuff.. -import org.doube.bonej.pqct.selectroi.*; //ROI selection.. -import org.doube.bonej.pqct.io.*; //image data -import java.awt.*; //Image, component for debugging... -import ij.plugin.filter.Info; -import ij.io.*; - -public class Get_Vertical_Flip implements PlugIn { - - - int sectorWidth; - int divisions; - int concentricSector; - int concentricDivisions; - boolean cOn; //Basic analyses - boolean mOn; //Mass distribution - boolean conOn; //Concentric rings analysis - boolean dOn; //Distribution analysis - boolean stOn; //Soft tissue analysis - boolean alphaOn; //Rotation angle - String resultString; - String imageInfo; - boolean flipHorizontal; - boolean flipVertical; - double resolution; - //Thresholds - double airThreshold; - double fatThreshold; - double muscleThreshold; - double marrowThreshold; - double softThreshold; - double rotationThreshold; - double areaThreshold; - double BMDThreshold; - - double scalingFactor; - double constant; - boolean flipDistribution; - boolean guessFlip; - boolean guessLarger; - boolean stacked; - boolean guessStacked; - boolean invertGuess; - boolean manualRotation; - boolean allowCleaving; - boolean preventPeeling; - boolean sleeveOn; - String roiChoice; - String roiChoiceSt; - String rotationChoice; - - - public void run(String arg) { - ImagePlus imp = WindowManager.getCurrentImage(); - if (imp == null) - return; - if (imp.getType() != ImagePlus.GRAY16){ - IJ.error("Distribution analysis expects 16-bit greyscale data"); - return; - } - /*Set sector widths and division numbers*/ - sectorWidth = 10; - divisions = 3; - concentricSector = 10; - concentricDivisions = 10; - - imageInfo = new Info().getImageInfo(imp,imp.getChannelProcessor()); - /*Check image calibration*/ - Calibration cal = imp.getCalibration(); - double[] calibrationCoefficients = {0,1}; - if (getInfoProperty(imageInfo,"Stratec File") == null){ - if (cal.getCoefficients() != null) - calibrationCoefficients = cal.getCoefficients(); - } else { - calibrationCoefficients = new double[2]; - /*Read calibration from TYP file database*/ - String typFileName = getInfoProperty(imageInfo,"Device"); - try { - InputStream ir = this.getClass().getClassLoader().getResourceAsStream("org/doube/bonej/pqct/typ/"+typFileName); - byte[] typFileData = new byte[ir.available()]; - ir.read(typFileData); - ir.close(); - String typFiledDataString = new String(typFileData,"ISO-8859-1"); - //break the typFileDataString into lines - StringTokenizer st = new StringTokenizer(typFiledDataString, "\n"); - Vector typFileLines = new Vector(); - while(st.hasMoreTokens()){ - typFileLines.add(st.nextToken()); - } - //Search for XSlope and XInter - String[] searchFor = {"XInter","XSlope"}; - for (int i = 0;i= 0){ //Found line - StringTokenizer st2 = new StringTokenizer(temp, "="); - Vector typFileLineTokens = new Vector(); - while(st2.hasMoreTokens()){ - typFileLineTokens.add(st2.nextToken().trim()); - } - calibrationCoefficients[i] = Double.valueOf(typFileLineTokens.get(1)); - } else { - calibrationCoefficients[i] = (double) i*1000.0; - } - } - calibrationCoefficients[1] /= 1000.0; //1.495 - } catch (Exception err){System.err.println("Error: "+err.getMessage());} - } - - resolution = cal.pixelWidth; - if (getInfoProperty(imageInfo,"Pixel Spacing")!= null){ - String temp = getInfoProperty(imageInfo,"Pixel Spacing"); - if (temp.indexOf("\\")!=-1){ - temp = temp.substring(0,temp.indexOf("\\")); - } - resolution = Double.valueOf(temp); - } - //Get parameters for scaling the image and for thresholding - GenericDialog dialog = new GenericDialog("Analysis parameters"); - - dialog.addCheckbox("Measurement_tube",false); - dialog.addNumericField("Air_threshold", -40, 4, 8, null); //Anything above this is fat or more dense - dialog.addNumericField("Fat threshold", 40, 4, 8, null); //Anything between this and air threshold is fat - dialog.addNumericField("Muscle_threshold", 40, 4, 8, null); //Anything above this is muscle or more dense - dialog.addNumericField("Marrow_threshold", 70, 4, 8, null); //Anything above this is muscle or more dense - dialog.addNumericField("Soft_tissue_threshold", 200.0, 4, 8, null); //Anything between this and muscle threshold is muscle - dialog.addNumericField("Rotation_threshold", 200.0, 4, 8, null); - dialog.addNumericField("Area threshold", 550.0, 4, 8, null); //550.0 - dialog.addNumericField("BMD threshold", 690.0, 4, 8, null); //690.0 - - - dialog.addNumericField("Scaling_coefficient (slope)", calibrationCoefficients[1], 4, 8, null); - dialog.addNumericField("Scaling_constant (intercept)",calibrationCoefficients[0], 4, 8, null); - //Get ROI selection - String[] choiceLabels = {"Bigger","Smaller","Left","Right","Top","Bottom","Central","Peripheral","SecondLargest","TwoLargestLeft","TwoLargestRight"}; - dialog.addChoice("Roi_selection", choiceLabels, choiceLabels[0]); - dialog.addCheckbox("Suppress_result_image",false); - dialog.addCheckbox("Manual_rotation",false); - dialog.addNumericField("Manual_alfa", 0.0, 4, 8, null); //690.0 - dialog.addCheckbox("Change_sign",false); - dialog.addCheckbox("Save_visual_result_image_on_disk",false); - dialog.addStringField("Image_save_path",Prefs.getDefaultDirectory(),40); - dialog.addHelp("http://bonej.org/densitydistribution"); - dialog.showDialog(); - - if (dialog.wasOKed()){ //Stop in case of cancel.. - sleeveOn = dialog.getNextBoolean(); - airThreshold = dialog.getNextNumber(); - fatThreshold = dialog.getNextNumber(); - muscleThreshold = dialog.getNextNumber(); - marrowThreshold = dialog.getNextNumber(); - softThreshold = dialog.getNextNumber(); - rotationThreshold = dialog.getNextNumber(); - areaThreshold = dialog.getNextNumber(); - BMDThreshold = dialog.getNextNumber(); - scalingFactor = dialog.getNextNumber(); - constant = dialog.getNextNumber(); - roiChoice = dialog.getNextChoice(); - boolean suppressImages = dialog.getNextBoolean(); - manualRotation = dialog.getNextBoolean(); - double manualAlfa = dialog.getNextNumber(); - boolean changeSign = dialog.getNextBoolean(); - boolean saveImageOnDisk = dialog.getNextBoolean(); - String imageSavePath = dialog.getNextString(); - ScaledImageData scaledImageData; - - - - boolean manualRoi = false; - boolean noFiltering = false; - String[] rotationLabels = {"According_to_Imax/Imin","Furthest_point","All_Bones_Imax/Imin","Not_selected_to_right","Selected_to_right"}; - String imageName; - if (getInfoProperty(imageInfo,"File Name")!= null){ - imageName = getInfoProperty(imageInfo,"File Name"); - }else{ - if(imp.getImageStackSize() == 1){ - imageName = imp.getTitle(); - imageInfo+="File Name:"+imageName+"\n"; - }else{ - imageName = imageInfo.substring(0,imageInfo.indexOf("\n")); - imageInfo+="File Name:"+imageName+"\n"; - } - } - - /*Look study special, images acquired prior to 2007 need to be flipped horizontally*/ - String checkDate = getInfoProperty(imageInfo,"Acquisition Date"); - if (checkDate.indexOf("2005") >-1 || checkDate.indexOf("2006") >-1){ - flipHorizontal = true; - } - short[] tempPointer = (short[]) imp.getProcessor().getPixels(); - int[] unsignedShort = new int[tempPointer.length]; - if (getInfoProperty(imageInfo,"Stratec File") == null){ //For unsigned short Dicom, which appears to be the default ImageJ DICOM... - for (int i=0;i>(i*8))& 0XFF; - } - tempImage.getProcessor().setColor(new Color(0,0,rgb[0])); - tempImage.getProcessor().drawPixel(x,y); - } - if (sieve[x+y*tempImage.getWidth()] == 2){ //Tint other side with red - int value = tempImage.getProcessor().getPixel(x,y); - int[] rgb = new int[3]; - for (int i = 0; i<3;++i){ - rgb[i] = (value >>(i*8))& 0XFF; - } - tempImage.getProcessor().setColor(new Color(rgb[2],0,0)); - tempImage.getProcessor().drawPixel(x,y); - } - if (sieve[x+y*tempImage.getWidth()] == 3){ //Tint other side with red - int value = tempImage.getProcessor().getPixel(x,y); - int[] rgb = new int[3]; - for (int i = 0; i<3;++i){ - rgb[i] = (value >>(i*8))& 0XFF; - } - tempImage.getProcessor().setColor(new Color(0,rgb[1],0)); - tempImage.getProcessor().drawPixel(x,y); - } - if (sieve[x+y*tempImage.getWidth()] == 4){ //Tint other side with red - int value = tempImage.getProcessor().getPixel(x,y); - int[] rgb = new int[3]; - for (int i = 0; i<3;++i){ - rgb[i] = (value >>(i*8))& 0XFF; - } - tempImage.getProcessor().setColor(new Color(rgb[2],0,rgb[0])); - tempImage.getProcessor().drawPixel(x,y); - } - } - } - //tempImage.setProcessor(tempImage.getProcessor().resize(1000)); - return tempImage; - } - - /*Add soft sieve*/ - ImagePlus addSoftTissueSieve(ImagePlus tempImage, byte[] sieve){ - for (int y = 0; y < tempImage.getHeight();++y) { - for (int x = 0; x < tempImage.getWidth();++x) { - if (sieve[x+y*tempImage.getWidth()] == 2){ //Tint fat area with yellow - int value = tempImage.getProcessor().getPixel(x,y); - int[] rgb = new int[3]; - for (int i = 0; i<3;++i){ - rgb[i] = (value >>(i*8))& 0XFF; - } - tempImage.getProcessor().setColor(new Color(rgb[2],rgb[1],0)); - tempImage.getProcessor().drawPixel(x,y); - } - if (sieve[x+y*tempImage.getWidth()] == 3){ //Tint muscle area with red - int value = tempImage.getProcessor().getPixel(x,y); - int[] rgb = new int[3]; - for (int i = 0; i<3;++i){ - rgb[i] = (value >>(i*8))& 0XFF; - } - tempImage.getProcessor().setColor(new Color(rgb[2],0,0)); - tempImage.getProcessor().drawPixel(x,y); - } - if (sieve[x+y*tempImage.getWidth()] == 4){ //Tint intra fat area with green - int value = tempImage.getProcessor().getPixel(x,y); - int[] rgb = new int[3]; - for (int i = 0; i<3;++i){ - rgb[i] = (value >>(i*8))& 0XFF; - } - tempImage.getProcessor().setColor(new Color(0,rgb[1],0)); - tempImage.getProcessor().drawPixel(x,y); - } - if (sieve[x+y*tempImage.getWidth()] == 5){ //Tint subcut fat area with purple - int value = tempImage.getProcessor().getPixel(x,y); - int[] rgb = new int[3]; - for (int i = 0; i<3;++i){ - rgb[i] = (value >>(i*8))& 0XFF; - } - tempImage.getProcessor().setColor(new Color(rgb[2],0,rgb[0])); - tempImage.getProcessor().drawPixel(x,y); - } - } - } - //tempImage.setProcessor(tempImage.getProcessor().resize(1000)); - return tempImage; - } - - /*Add bone sieve*/ - ImagePlus addBoneSieve(ImagePlus tempImage, byte[] sieve,double[] scaledImage, double marrowThreshold){ - for (int y = 0; y < tempImage.getHeight();++y) { - for (int x = 0; x < tempImage.getWidth();++x) { - if (sieve[x+y*tempImage.getWidth()] == 1){ //Tint bone area with purple - int value = tempImage.getProcessor().getPixel(x,y); - int[] rgb = new int[3]; - for (int i = 0; i<3;++i){ - rgb[i] = (value >>(i*8))& 0XFF; - } - tempImage.getProcessor().setColor(new Color(rgb[2],0,rgb[0])); - tempImage.getProcessor().drawPixel(x,y); - } - if (sieve[x+y*tempImage.getWidth()] == 1 && scaledImage[x+y*tempImage.getWidth()] <=marrowThreshold){ //Tint marrow area with green - int value = tempImage.getProcessor().getPixel(x,y); - int[] rgb = new int[3]; - for (int i = 0; i<3;++i){ - rgb[i] = (value >>(i*8))& 0XFF; - } - if (rgb[0] < 255-50){ - rgb[0]+=50; - } - tempImage.getProcessor().setColor(new Color(0,0,rgb[0])); - tempImage.getProcessor().drawPixel(x,y); - } - } - } - return tempImage; - } - - /*addDenstiyDistribution*/ - ImagePlus addRadii(ImagePlus tempImage,double alfa,double[] marrowCenter,Vector pindColor, - double[] R, double[] R2, double[] Theta){ - //Draw unrotated radii - for(int i = 0; i< 360;i++) {//45;i++) {// - int x = ((int) (marrowCenter[0]+R[i]*Math.cos(Theta[i]))); - int y = ((int) (marrowCenter[1]+R[i]*Math.sin(Theta[i]))); - double colorScale = ((double) pindColor.get(i))/359.0; - tempImage.getProcessor().setColor(new Color((int) (255.0*colorScale),0,(int) (255.0*(1.0-colorScale)))); - tempImage.getProcessor().drawPixel(x,y); - x = ((int) (marrowCenter[0]+R2[i]*Math.cos(Theta[i]))); - y = ((int) (marrowCenter[1]+R2[i]*Math.sin(Theta[i]))); - tempImage.getProcessor().setColor(new Color(0,(int) (255.0*colorScale),(int) (255.0*(1.0-colorScale)))); - tempImage.getProcessor().drawPixel(x,y); - } - return tempImage; - } - ImagePlus addMarrowCenter(ImagePlus tempImage,double alfa,double[] marrowCenter){ - /*plot marrowCenter*/ - for(int i = 0; i< 10;i++) {//45;i++) {// - int x = ((int) (marrowCenter[0]+i)); - int y = ((int) (marrowCenter[1])); - tempImage.getProcessor().setColor(new Color(0,255,255)); - tempImage.getProcessor().drawPixel(x,y); - x = (int) (marrowCenter[0]); - y = (int) (marrowCenter[1]+i); - tempImage.getProcessor().setColor(new Color(255,0,255)); - tempImage.getProcessor().drawPixel(x,y); - /*Plot rotated axes...*/ - x = ((int) ((double) marrowCenter[0]+((double) i)*Math.cos(-alfa/180*Math.PI))); - y = ((int) ((double) marrowCenter[1]+((double) i)*Math.sin(-alfa/180*Math.PI))); - tempImage.getProcessor().setColor(new Color(0,255,0)); - tempImage.getProcessor().drawPixel(x,y); - x = ((int) ((double) marrowCenter[0]+((double) -i)*Math.sin(-alfa/180*Math.PI))); - y = ((int) ((double) marrowCenter[1]+((double) i)*Math.cos(-alfa/180*Math.PI))); - tempImage.getProcessor().setColor(new Color(0,0,255)); - tempImage.getProcessor().drawPixel(x,y); - } - return tempImage; - } - - ImagePlus addRotate(ImagePlus tempImage,double alfa){ - tempImage.getProcessor().setInterpolate(true); - tempImage.getProcessor().rotate(alfa); - return tempImage; - } - - /*Concentric rings distribution result image*/ - ImagePlus addPeriRadii(ImagePlus tempImage,double[] marrowCenter,Vector pindColor, double[] R, double[] Theta){ - //Draw unrotated radii - for(int i = 0; i< Theta.length;i++) {//45;i++) {// - int x = ((int) (marrowCenter[0]+R[i]*Math.cos(Theta[i]))); - int y = ((int) (marrowCenter[1]+R[i]*Math.sin(Theta[i]))); - double colorScale = ((double) pindColor.get(i))/359.0; - tempImage.getProcessor().setColor(new Color(0,(int) (255.0*colorScale),(int) (255.0*(1.0-colorScale)))); - tempImage.getProcessor().drawPixel(x,y); - } - return tempImage; - } - - void writeHeader(TextPanel textPanel){ - String[] propertyNames = {"File Name","Soft tissue side [2 = left, 1 = right]"}; - - String headings = ""; - for (int i = 0;iStacks, "Check Voxel Depth", org.doube.util.VoxelDepthChecker Plugins>Stacks, "Interpolate ROIs", org.doube.util.RoiInterpolator Plugins>pQCT, "Distribution Analysis", org.doube.bonej.pqct.Distribution_Analysis -#Plugins>pQCT, "Get Vertical Flip", org.doube.bonej.pqct.Get_Vertical_Flip Plugins>pQCT, "Export Stratec Header", org.doube.bonej.pqct.Export_Header Plugins>pQCT, "Strip Stratec Header", org.doube.bonej.pqct.Strip_Stratec_File_Header