@@ -470,19 +470,23 @@ public static bool RadIcon(string str)
470470 #region DigitalMicrograph
471471 private static bool DM ( string str )
472472 {
473- try
473+ // try
474474 {
475475 Ring . Comments = "" ;
476476 var t = new DigitalMicrograph . Loader ( str ) ;
477477
478478 double pixelScale = ( float ) t . Tag [ "ImageList" ] . Tag [ "1" ] . Tag [ "ImageData" ] . Tag [ "Calibrations" ] . Tag [ "Dimension" ] . Tag [ "0" ] . Tag [ "Scale" ] . Values [ 0 ] ;
479479
480480 double accVol = 200000 ;
481- var test = t . Tag [ "ImageList" ] . Tag [ "1" ] . Tag [ "ImageTags" ] . Tag [ "Microscope Info" ] . Tag [ "Voltage" ] . Values [ 0 ] ;
482- if ( test is float accF )
483- accVol = ( double ) accF ;
484- else if ( test is double accD )
485- accVol = accD ;
481+ try
482+ {
483+ var test = t . Tag [ "ImageList" ] . Tag [ "1" ] . Tag [ "ImageTags" ] . Tag [ "Microscope Info" ] . Tag [ "Voltage" ] . Values [ 0 ] ;
484+ if ( test is float accF )
485+ accVol = ( double ) accF ;
486+ else if ( test is double accD )
487+ accVol = accD ;
488+ }
489+ catch { }
486490
487491 var pixelSize = 0.1 ;
488492 //CCDカメラの場合
@@ -507,17 +511,52 @@ private static bool DM(string str)
507511 int imageWidth = ( int ) ( uint ) t . Tag [ "ImageList" ] . Tag [ "1" ] . Tag [ "ImageData" ] . Tag [ "Dimensions" ] . Tag [ "0" ] . Values [ 0 ] ;
508512 int imageHeight = ( int ) ( uint ) t . Tag [ "ImageList" ] . Tag [ "1" ] . Tag [ "ImageData" ] . Tag [ "Dimensions" ] . Tag [ "1" ] . Values [ 0 ] ;
509513 Ring . SrcImgSize = new Size ( imageWidth , imageHeight ) ;
510-
511- dynamic intensity ;
512- if ( t . Tag [ "ImageList" ] . Tag [ "1" ] . Tag [ "ImageData" ] . Tag [ "Data" ] . Values != null && t . Tag [ "ImageList" ] . Tag [ "1" ] . Tag [ "ImageData" ] . Tag [ "Data" ] . Values . Length != 0 )
514+
515+ var obj = t . Tag [ "ImageList" ] . Tag [ "1" ] . Tag [ "ImageData" ] . Tag [ "Data" ] . Values ;
516+ if ( obj != null && obj . Length != 0 )
513517 {
514- object o = t . Tag [ "ImageList" ] . Tag [ "1" ] . Tag [ "ImageData" ] . Tag [ "Data" ] . Values [ 0 ] ;
515- if ( o . GetType ( ) == typeof ( float ) )
516- intensity = t . Tag [ "ImageList" ] . Tag [ "1" ] . Tag [ "ImageData" ] . Tag [ "Data" ] . Values . Select ( v => ( float ) v ) . ToArray ( ) ;
517- else if ( o . GetType ( ) == typeof ( uint ) )
518- intensity = t . Tag [ "ImageList" ] . Tag [ "1" ] . Tag [ "ImageData" ] . Tag [ "Data" ] . Values . Select ( v => ( uint ) v ) . ToArray ( ) ;
519- else if ( o . GetType ( ) == typeof ( int ) )
520- intensity = t . Tag [ "ImageList" ] . Tag [ "1" ] . Tag [ "ImageData" ] . Tag [ "Data" ] . Values . Select ( v => ( int ) v ) . ToArray ( ) ;
518+ dynamic intensity ;
519+
520+ //object o = t.Tag["ImageList"].Tag["1"].Tag["ImageData"].Tag["Data"].Values[0];
521+ if ( obj [ 0 ] . GetType ( ) == typeof ( float ) )
522+ {
523+ if ( obj . Length == imageHeight * imageWidth ) //実数データの時
524+ intensity = obj . Select ( v => ( float ) v ) . ToArray ( ) ;
525+ else //複素数データの時 20251210土山さんメール参照
526+ {
527+ Ring . DigitalMicrographProperty . IsFFT = true ;
528+ var tmp1 = obj . Select ( v => ( float ) v ) . ToArray ( ) ;
529+ intensity = new double [ imageHeight * imageWidth ] ;
530+
531+ for ( int i = 0 ; i < tmp1 . Length ; i += 2 )
532+ {
533+ int row = ( i / 2 ) / ( imageWidth / 2 + 1 ) ;
534+ int col = ( i / 2 ) % ( imageWidth / 2 + 1 ) ;
535+ var magnitude = Math . Sqrt ( tmp1 [ i ] * tmp1 [ i ] + tmp1 [ i + 1 ] * tmp1 [ i + 1 ] ) ;
536+ if ( col == 0 )
537+ intensity [ row * imageWidth + imageWidth / 2 ] = magnitude ;
538+ else if ( imageWidth % 2 == 0 && col == imageWidth / 2 )
539+ intensity [ row * imageWidth ] = magnitude ;
540+ else if ( imageHeight % 2 == 0 && row == 0 )
541+ {
542+ intensity [ imageWidth / 2 + col ] = magnitude ;
543+ intensity [ imageWidth / 2 - col ] = magnitude ;
544+ }
545+ else
546+ {
547+ intensity [ row * imageWidth + imageWidth / 2 + col ] = magnitude ;
548+ if ( imageHeight % 2 == 0 )
549+ intensity [ ( imageHeight - row ) * imageWidth + imageWidth / 2 - col ] = magnitude ;
550+ else
551+ intensity [ ( imageHeight - row - 1 ) * imageWidth + imageWidth / 2 - col ] = magnitude ;
552+ }
553+ }
554+ }
555+ }
556+ else if ( obj [ 0 ] . GetType ( ) == typeof ( uint ) )
557+ intensity = obj . Select ( v => ( uint ) v ) . ToArray ( ) ;
558+ else if ( obj [ 0 ] . GetType ( ) == typeof ( int ) )
559+ intensity = obj . Select ( v => ( int ) v ) . ToArray ( ) ;
521560 else
522561 return false ;
523562
@@ -529,11 +568,11 @@ private static bool DM(string str)
529568 //Ring.BitsPerPixels = t.BitsPerSampleGray;
530569 Ring . ImageType = Ring . ImageTypeEnum . DM ;
531570 }
532- catch ( Exception e )
533- {
534- MessageBox . Show ( e . Message ) ;
535- return false ;
536- }
571+ // catch (Exception e)
572+ // {
573+ // MessageBox.Show(e.Message);
574+ // return false;
575+ // }
537576 return true ;
538577 }
539578 #endregion
0 commit comments