T O P I C R E V I E W |
Dave |
Posted - Dec 17 2013 : 09:04:27 Hello there,
I want to add a TIFF file to a Dicom file (wich is not the real problem) but I need it te be in grayscale (256 colors).
The original Tiff has 256 colors but after saving it to a Dicom file or another tiff, this is changed into 16 milion colors. So I try to use the procedure "Proc.ConvertToGray". Althoug I stil have 16 milion colors and the property "Photometric Interpretian" say's RGB, this should be "MONOCHROME2".
In attachment the Original tiff file.
This is the source in Delphi: (imgViewDicom1 is of type TImageEnView)
procedure TForm1.btnTestClick(Sender: TObject); var fileName, tmp: string; begin
imgViewDicom1.IO.LoadFromFileTIFF(edtConvert.Text);
lblBPS.Caption := IntToStr(imgViewDicom1.IO.Params.BitsPerSample); lblSPP.Caption := IntToStr(imgViewDicom1.IO.Params.SamplesPerPixel);
imgViewDicom1.Proc.ConvertToGray;
tmp := TimeToStr(Time); fileName := 'C:\Temp\TestDicom_' + StringReplace(tmp,':','_', [rfReplaceAll, rfIgnoreCase]) + '.dcm'; imgViewDicom1.IO.SaveToFileDICOM( fileName );
fileName := 'C:\Temp\TestDicom_' + StringReplace(tmp,':','_', [rfReplaceAll, rfIgnoreCase]) + '.tif'; imgViewDicom1.IO.SaveToFileTIFF( fileName ); end;
Greetings and thanx in advance
 |
4 L A T E S T R E P L I E S (Newest First) |
Dave |
Posted - Jan 07 2014 : 01:45:27 Seems to work, thnx, and a healthy and happy 2014.
Dave |
w2m |
Posted - Jan 02 2014 : 10:41:48 The only thing I can think of is: myView2.LegacyBitmap := False; // Do not use TBitmap myView2.IO.NativePixelFormat := True; // Use the original pixel format
LegacyBitmap must be False to enable NativePixelFormat. Also, use of NativePixelFormat will prevent execution of some image processing operations.
By doing this however, you loose access the image in Bitmap and must use IEBitmap.
William Miller Adirondack Software & Graphics Email: w2m@frontiernet.net EBook: http://www.imageen.com/ebook/ Apprehend: http://www.frontiernet.net/~w2m/index.html |
Dave |
Posted - Dec 18 2013 : 02:38:13 Thnx for the fast reply.
This seems to work but now I have the problem when I save my file as a Dicom file ...
// next OK myView2.IO.LoadFromFileTIFF(edtTIF.Text);
// next ok myView2.Proc.ConvertToGray; // (next) I need 16 in stead of 8, is also OK myView2.IO.Params.BitsPerSample := 16; myView2.IO.Params.SamplesPerPixel := 1;
// next ok, I just do this for testing the tiff file, nothing more myView2.IO.SaveToFileTIFF( 'TestTiff.tif' );
// troubles, values are changed myView2.IO.SaveToFileDICOM( TestDicom.dcm );
When I now look at the dicom file (using MicroDicom) I notice that the next tags have the wrong values:
Tag(0028, 0002) SamplesPerPixel is 3 in stead of 1 Tag(0028, 0004) Photometric Interpretion is RGB (should be MONOCHROME2 I supose) Maybe it has something to do with the Header tags ...
...
PS: is it mandatory to add the extention to the filename (in my case .dcm) when saving as Dicom
|
w2m |
Posted - Dec 17 2013 : 09:38:33 Most of the time when you use an ImageEnProc it converts the image to RGB24-bit and then does the operation, so ConvertToGray does not convert the image to 256 color... in fact it converts the image to 24-bit before setting the RGB channels.
ConvertToGray This method converts the selected region to gray levels. The image always will be in true color (16M of colors). When LegacyBitmap is True, ImageEn can handle only black/white (pf1bit) or true color images (pf24bit). ConvertToGray just sets the R,G,B channels to the same value.
To convert to a 256 color grayscale 8-bit image try this:
ImageEnView1.Proc.ConverttoGray;
ImageEnView1.IO.Params.BitsPerSample := 8;
ImageEnView1.IO.Params.SamplesPerPixel := 1; ...then save the file.
William Miller Adirondack Software & Graphics Email: w2m@frontiernet.net EBook: http://www.imageen.com/ebook/ Apprehend: http://www.frontiernet.net/~w2m/index.html
|
|
|