Good Morning,
I have written a program which: Imports 4 DICOM images into imageJ each image consisting of a single strip Adds all the images together Draws a line down the centre of each strip Here's the code: // import ij.*; import ij.process.*; import ij.gui.*; import java.awt.*; import ij.plugin.*; import ij.io.*; import ij.measure.*; public class Colli_spokes2 implements PlugIn { int i =0; public ImageProcessor Openingdicom() //This method opens the dicom files and return the imageprocessor of each selected image { OpenDialog od = new OpenDialog("Open.....", null); Opener op = new Opener(); String directory = od.getDirectory(); String filename = od.getFileName(); ImagePlus imp = op.openImage(directory, filename); ImageProcessor ips = imp.getProcessor(); return ips; } public void run(String arg) { ImageProcessor ip1 = Openingdicom(); //IJ.run("Query Dicom Header", "3002,0011"); ImagePlus imp1 = new ImagePlus("Colli", ip1); int[] start = new int[6]; int[] end = new int[6]; ip1.multiply(0.5); ImageProcessor ip2 = Openingdicom(); ip2.multiply(0.5); ImageProcessor ip3 = Openingdicom(); ip3.multiply(0.5); ImageProcessor ip4 = Openingdicom(); ip4.multiply(0.5); ip1.copyBits(ip2, 0,0,Blitter.ADD); ip1.copyBits(ip3, 0,0, Blitter.ADD); ip1.copyBits(ip4, 0, 0, Blitter.ADD); imp1.show(); ip1.autoThreshold(); imp1.updateAndDraw(); int qheight = (ip1.getHeight()/4); int tqheight = qheight*3; int y =0; for(int u =0; u<(ip1.getWidth()-1); u++){ int Pixval1 = ip1.getPixel(u, qheight); int Pixval2 = ip1.getPixel(u+1,qheight); if((Pixval2 - Pixval1) != 0 ){ start[y] = u; y++; } } y=0; for(int u=0; u<(ip1.getWidth()-1); u++){ int Pixval1 = ip1.getPixel(u, tqheight); int Pixval2 = ip1.getPixel(u+1,tqheight); if((Pixval2 - Pixval1) != 0){ end[y] = u; y++; } } Line col1 = new Line((start[0])+((start[1]-start[0])/2), qheight, (end[4])+((end[5]-end[4])/2), tqheight); Line col2 = new Line((start[2])+((start[3]-start[2])/2), qheight, (end[2])+((end[3]-end[2])/2), tqheight); Line col3 = new Line((start[4])+((start[5]-start[4])/2), qheight, (end[0])+((end[1]-end[0])/2), tqheight); col1.drawPixels(ip1); col2.drawPixels(ip1); col3.drawPixels(ip1); } } This code works fine, however I would also like to retrieve the DICOM header information about the pixel spacing. I was hoping to achieve this with the command IJ.run("Query Dicom Header", "3002,0011") however when this is added to the code and is compiled and run, ImageJ completely shuts down. This also happens if I only use the command IJ.run("Query Dicom Header"). Can anyone suggest why this happens? I'm open to other methods of retrieving DICOM header information automatically. Thanks |
On May 9, 2012, at 4:31 AM, Gary wrote:
> Good Morning, > > I have written a program which: > > Imports 4 DICOM images into imageJ each image consisting of a single strip > Adds all the images together > Draws a line down the centre of each strip You can retrieve the value of the DICOM Image Plane Pixel Spacing tag using String pixelSpacing = DicomTools.getTag(imp, "3002,0011"); where 'imp' is an ImagePlus object that contains a DICOM image. In a macro, use pixelSpacing = getInfo("3002,0011"; DicomTools.getTag() will return null if the 3002,0011 tag is missing and the getInfo() macro function will return "". -wayne > Here's the code: > // > > import ij.*; > import ij.process.*; > import ij.gui.*; > import java.awt.*; > import ij.plugin.*; > import ij.io.*; > import ij.measure.*; > > public class Colli_spokes2 implements PlugIn { > > int i =0; > > public ImageProcessor Openingdicom() //This method opens the dicom files and > return the imageprocessor of each selected image > { > OpenDialog od = new OpenDialog("Open.....", null); > Opener op = new Opener(); > String directory = od.getDirectory(); > String filename = od.getFileName(); > ImagePlus imp = op.openImage(directory, filename); > ImageProcessor ips = imp.getProcessor(); > > return ips; > } > public void run(String arg) { > > ImageProcessor ip1 = Openingdicom(); > //IJ.run("Query Dicom Header", "3002,0011"); > ImagePlus imp1 = new ImagePlus("Colli", ip1); > int[] start = new int[6]; > int[] end = new int[6]; > ip1.multiply(0.5); > ImageProcessor ip2 = Openingdicom(); > ip2.multiply(0.5); > ImageProcessor ip3 = Openingdicom(); > ip3.multiply(0.5); > ImageProcessor ip4 = Openingdicom(); > ip4.multiply(0.5); > > > ip1.copyBits(ip2, 0,0,Blitter.ADD); > ip1.copyBits(ip3, 0,0, Blitter.ADD); > ip1.copyBits(ip4, 0, 0, Blitter.ADD); > imp1.show(); > ip1.autoThreshold(); > > > imp1.updateAndDraw(); > > int qheight = (ip1.getHeight()/4); > int tqheight = qheight*3; > int y =0; > > for(int u =0; u<(ip1.getWidth()-1); u++){ > int Pixval1 = ip1.getPixel(u, qheight); > int Pixval2 = ip1.getPixel(u+1,qheight); > > > if((Pixval2 - Pixval1) != 0 ){ > start[y] = u; > y++; > } > } > > y=0; > > for(int u=0; u<(ip1.getWidth()-1); u++){ > int Pixval1 = ip1.getPixel(u, tqheight); > int Pixval2 = ip1.getPixel(u+1,tqheight); > > if((Pixval2 - Pixval1) != 0){ > end[y] = u; > y++; > } > } > > > Line col1 = new Line((start[0])+((start[1]-start[0])/2), qheight, > (end[4])+((end[5]-end[4])/2), tqheight); > Line col2 = new Line((start[2])+((start[3]-start[2])/2), qheight, > (end[2])+((end[3]-end[2])/2), tqheight); > Line col3 = new Line((start[4])+((start[5]-start[4])/2), qheight, > (end[0])+((end[1]-end[0])/2), tqheight); > > col1.drawPixels(ip1); > col2.drawPixels(ip1); > col3.drawPixels(ip1); > > } > } > > This code works fine, however I would also like to retrieve the DICOM header > information about the pixel spacing. I was hoping to achieve this with the > command IJ.run("Query Dicom Header", "3002,0011") however when this is added to > the code and is compiled and run, ImageJ completely shuts down. This also > happens if I only use the command IJ.run("Query Dicom Header"). > > Can anyone suggest why this happens? > > I'm open to other methods of retrieving DICOM header information automatically. > > Thanks |
Free forum by Nabble | Edit this page |