#include <processor.h>
Inheritance diagram for EMAN::Phase180Processor:
Protected Member Functions | |
void | swap_corners_180 (EMData *image) |
swap_corners_180 - works on 2D and 3D images | |
void | swap_central_slices_180 (EMData *image) |
swap_central_slices_180 - works on 2D and 3D images | |
void | fourier_phaseshift180 (EMData *image) |
fourier_phaseshift180 - fourier phase shift by 180 this function is called internally if the argument to the process_inplace function is complex. |
It contains functionality common to the PhaseToCenterProcessor and PhaseToCornerProcessor processors
Definition at line 4830 of file processor.h.
void Phase180Processor::fourier_phaseshift180 | ( | EMData * | image | ) | [protected] |
fourier_phaseshift180 - fourier phase shift by 180 this function is called internally if the argument to the process_inplace function is complex.
image | the image to be operated upon |
ImageFormatException | if the image is not in complex format |
Definition at line 4795 of file processor.cpp.
References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageFormatException, EMAN::EMData::is_complex(), and rdata.
Referenced by EMAN::PhaseToCenterProcessor::process_inplace(), and EMAN::PhaseToCornerProcessor::process_inplace().
04796 { 04797 if ( !image->is_complex() ) throw ImageFormatException("Can not handle images that are not complex in fourier phase shift 180"); 04798 04799 int nx = image->get_xsize(); 04800 int ny = image->get_ysize(); 04801 int nz = image->get_zsize(); 04802 04803 int nxy = nx * ny; 04804 04805 float *rdata = image->get_data(); 04806 04807 // Who uses this function? It doesn't work for odd images, and it will give incorrect results for some even images 04808 // d.woolford, March 15 2009 04809 int of=0; 04810 if (((ny/2)%2)+((nz/2)%2)==1) of=1; 04811 04812 for (int k = 0; k < nz; k++) { 04813 size_t k2 = (size_t)k * nxy; 04814 04815 for (int j = 0; j < ny; j++) { 04816 int i = ((k+j)%2==of?2:0); 04817 size_t j2 = j * nx + k2; 04818 04819 for (; i < nx; i += 4) { 04820 rdata[i + j2] *= -1.0f; 04821 rdata[i + j2 + 1] *= -1.0f; 04822 } 04823 } 04824 } 04825 }
void Phase180Processor::swap_central_slices_180 | ( | EMData * | image | ) | [protected] |
swap_central_slices_180 - works on 2D and 3D images
swaps pixels values in central slices, only required if the image has one or more odd dimensions. Should be used striclty in conjunction with swap_central_slices_180 function and never called by anyone except for PhaseToCenterProcessor and PhaseToCornerProcessor classes. Highly specialised function to handle all cases of even and oddness
image | the image to be operated upon |
ImageDimensionException | if the image is 1D | |
NullPointerException | if the image is null |
Definition at line 4924 of file processor.cpp.
References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, and rdata.
Referenced by EMAN::PhaseToCenterProcessor::process_inplace(), and EMAN::PhaseToCornerProcessor::process_inplace().
04925 { 04926 int nx = image->get_xsize(); 04927 int ny = image->get_ysize(); 04928 int nz = image->get_zsize(); 04929 04930 int xodd = (nx % 2) == 1; 04931 int yodd = (ny % 2) == 1; 04932 int zodd = (nz % 2) == 1; 04933 04934 int nxy = nx * ny; 04935 04936 float *rdata = image->get_data(); 04937 04938 if ( ny == 1 && nz == 1 ){ 04939 throw ImageDimensionException("Error, cannot handle 1D images. This function should not have been called"); 04940 } 04941 else if ( nz == 1 ) { 04942 float tmp; 04943 if ( yodd ) { 04944 // Iterate along middle row, swapping values where appropriate 04945 int r = ny/2; 04946 for ( int c = 0; c < nx/2; ++c ) { 04947 int idx1 = r*nx + c; 04948 int idx2 = r*nx + c + nx/2+ xodd; 04949 tmp = rdata[idx1]; 04950 rdata[idx1] = rdata[idx2]; 04951 rdata[idx2] = tmp; 04952 } 04953 } 04954 04955 if ( xodd ) { 04956 // Iterate along the central column, swapping values where appropriate 04957 int c = nx/2; 04958 for ( int r = 0; r < ny/2; ++r ) { 04959 int idx1 = r*nx + c; 04960 int idx2 = (r+ny/2+yodd)*nx + c; 04961 tmp = rdata[idx1]; 04962 rdata[idx1] = rdata[idx2]; 04963 rdata[idx2] = tmp; 04964 } 04965 } 04966 } 04967 else // nx && ny && nz are greater than 1 04968 { 04969 float tmp; 04970 if ( xodd ) { 04971 // Iterate along the x = nx/2 slice, swapping values where appropriate 04972 int c = nx/2; 04973 size_t idx1, idx2; 04974 for( int s = 0; s < nz/2; ++s ) { 04975 for ( int r = 0; r < ny/2; ++r ) { 04976 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04977 idx2 = (s+nz/2+zodd)*(size_t)nxy+(r+ny/2+yodd)*(size_t)nx+c; 04978 tmp = rdata[idx1]; 04979 rdata[idx1] = rdata[idx2]; 04980 rdata[idx2] = tmp; 04981 } 04982 } 04983 04984 for( int s = nz-1; s >= (nz/2+zodd); --s ) { 04985 for ( int r = 0; r < ny/2; ++r ) { 04986 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04987 idx2 = (s-nz/2-zodd)*(size_t)nxy+(r+ny/2+yodd)*(size_t)nx+c; 04988 tmp = rdata[idx1]; 04989 rdata[idx1] = rdata[idx2]; 04990 rdata[idx2] = tmp; 04991 } 04992 } 04993 } 04994 if ( yodd ) { 04995 // Iterate along the y = ny/2 slice, swapping values where appropriate 04996 int r = ny/2; 04997 size_t idx1, idx2; 04998 for( int s = 0; s < nz/2; ++s ) { 04999 for ( int c = 0; c < nx/2; ++c ) { 05000 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 05001 idx2 =(s+nz/2+zodd)*(size_t)nxy+(size_t)r*nx+c+nx/2+xodd; 05002 tmp = rdata[idx1]; 05003 rdata[idx1] = rdata[idx2]; 05004 rdata[idx2] = tmp; 05005 } 05006 } 05007 05008 for( int s = nz-1; s >= (nz/2+zodd); --s ) { 05009 for ( int c = 0; c < nx/2; ++c ) { 05010 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 05011 idx2 = (s-nz/2-zodd)*(size_t)nxy+(size_t)r*nx+c+nx/2+xodd; 05012 tmp = rdata[idx1]; 05013 rdata[idx1] = rdata[idx2]; 05014 rdata[idx2] = tmp; 05015 } 05016 } 05017 } 05018 if ( zodd ) { 05019 // Iterate along the z = nz/2 slice, swapping values where appropriate 05020 int s = nz/2; 05021 size_t idx1, idx2; 05022 for( int r = 0; r < ny/2; ++r ) { 05023 for ( int c = 0; c < nx/2; ++c ) { 05024 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 05025 idx2 = (size_t)s*nxy+(r+ny/2+yodd)*(size_t)nx+c+nx/2+xodd; 05026 tmp = rdata[idx1]; 05027 rdata[idx1] = rdata[idx2]; 05028 rdata[idx2] = tmp; 05029 } 05030 } 05031 05032 for( int r = ny-1; r >= (ny/2+yodd); --r ) { 05033 for ( int c = 0; c < nx/2; ++c ) { 05034 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 05035 idx2 = (size_t)s*nxy+(r-ny/2-yodd)*(size_t)nx+c+nx/2+xodd; 05036 tmp = rdata[idx1]; 05037 rdata[idx1] = rdata[idx2]; 05038 rdata[idx2] = tmp; 05039 } 05040 } 05041 } 05042 } 05043 }
void Phase180Processor::swap_corners_180 | ( | EMData * | image | ) | [protected] |
swap_corners_180 - works on 2D and 3D images
Implements the conventional 180 degree phase shift required to put the center of the image at the bottom left of the image - is used in conjunction with swap_central_slices_180 if any of the image dimensions are odd, but by itself will perform the entire operation on even images. This functions is never called by anyone except for the PhaseToCenterProcessor and PhaseToCornerProcessor classes. Highly specialised function to handle all cases of even and oddness
image | the image to be operated upon |
ImageDimensionException | if the image is 1D | |
NullPointerException | if the image is null |
Definition at line 4827 of file processor.cpp.
References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, and rdata.
Referenced by EMAN::PhaseToCenterProcessor::process_inplace(), and EMAN::PhaseToCornerProcessor::process_inplace().
04828 { 04829 int nx = image->get_xsize(); 04830 int ny = image->get_ysize(); 04831 int nz = image->get_zsize(); 04832 04833 int xodd = (nx % 2) == 1; 04834 int yodd = (ny % 2) == 1; 04835 int zodd = (nz % 2) == 1; 04836 04837 int nxy = nx * ny; 04838 04839 float *rdata = image->get_data(); 04840 04841 if ( ny == 1 && nz == 1 ){ 04842 throw ImageDimensionException("Error, cannot handle 1D images. This function should not have been called"); 04843 } 04844 else if ( nz == 1 ) { 04845 04846 // Swap the bottom left and top right corners 04847 for ( int r = 0; r < ny/2; ++r ) { 04848 for ( int c = 0; c < nx/2; ++c) { 04849 int idx1 = r*nx + c; 04850 int idx2 = (r+ny/2+yodd)*nx + c + nx/2+xodd; 04851 float tmp = rdata[idx1]; 04852 rdata[idx1] = rdata[idx2]; 04853 rdata[idx2] = tmp; 04854 } 04855 } 04856 04857 // Swap the top left and bottom right corners 04858 for ( int r = ny-1; r >= (ny/2+yodd); --r ) { 04859 for ( int c = 0; c < nx/2; ++c) { 04860 int idx1 = r*nx + c; 04861 int idx2 = (r-ny/2-yodd)*nx + c + nx/2+xodd; 04862 float tmp = rdata[idx1]; 04863 rdata[idx1] = rdata[idx2]; 04864 rdata[idx2] = tmp; 04865 } 04866 } 04867 } 04868 else // nx && ny && nz are greater than 1 04869 { 04870 float tmp; 04871 // Swap the bottom left front and back right top quadrants 04872 size_t idx1, idx2; 04873 04874 for ( int s = 0; s < nz/2; ++s ) { 04875 for ( int r = 0; r < ny/2; ++r ) { 04876 for ( int c = 0; c < nx/2; ++ c) { 04877 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04878 idx2 = (s+nz/2+zodd)*(size_t)nxy+(r+ny/2+yodd)*(size_t)nx+c+nx/2+xodd; 04879 tmp = rdata[idx1]; 04880 rdata[idx1] = rdata[idx2]; 04881 rdata[idx2] = tmp; 04882 } 04883 } 04884 } 04885 // Swap the bottom right front and back left top quadrants 04886 for ( int s = 0; s < nz/2; ++s ) { 04887 for ( int r = 0; r < ny/2; ++r ) { 04888 for ( int c = nx-1; c >= (nx/2+xodd); --c) { 04889 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04890 idx2 = (s+nz/2+zodd)*(size_t)nxy+(r+ny/2+yodd)*(size_t)nx+c-nx/2-xodd; 04891 tmp = rdata[idx1]; 04892 rdata[idx1] = rdata[idx2]; 04893 rdata[idx2] = tmp; 04894 } 04895 } 04896 } 04897 // Swap the top right front and back left bottom quadrants 04898 for ( int s = 0; s < nz/2; ++s ) { 04899 for ( int r = ny-1; r >= (ny/2+yodd); --r ) { 04900 for ( int c = nx-1; c >= (nx/2+xodd); --c) { 04901 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04902 idx2 = (s+nz/2+zodd)*(size_t)nxy+(r-ny/2-yodd)*(size_t)nx+c-nx/2-xodd; 04903 tmp = rdata[idx1]; 04904 rdata[idx1] = rdata[idx2]; 04905 rdata[idx2] = tmp; 04906 } 04907 } 04908 } 04909 // Swap the top left front and back right bottom quadrants 04910 for ( int s = 0; s < nz/2; ++s ) { 04911 for ( int r = ny-1; r >= (ny/2+yodd); --r ) { 04912 for ( int c = 0; c < nx/2; ++c) { 04913 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04914 idx2 = (s+nz/2+zodd)*(size_t)nxy+(r-ny/2-yodd)*(size_t)nx+c+nx/2+xodd; 04915 tmp = rdata[idx1]; 04916 rdata[idx1] = rdata[idx2]; 04917 rdata[idx2] = tmp; 04918 } 04919 } 04920 } 04921 } 04922 }