#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 4791 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 4754 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().
04755 { 04756 if ( !image->is_complex() ) throw ImageFormatException("Can not handle images that are not complex in fourier phase shift 180"); 04757 04758 int nx = image->get_xsize(); 04759 int ny = image->get_ysize(); 04760 int nz = image->get_zsize(); 04761 04762 int nxy = nx * ny; 04763 04764 float *rdata = image->get_data(); 04765 04766 // Who uses this function? It doesn't work for odd images, and it will give incorrect results for some even images 04767 // d.woolford, March 15 2009 04768 int of=0; 04769 if (((ny/2)%2)+((nz/2)%2)==1) of=1; 04770 04771 for (int k = 0; k < nz; k++) { 04772 size_t k2 = k * nxy; 04773 04774 for (int j = 0; j < ny; j++) { 04775 int i = ((k+j)%2==of?2:0); 04776 size_t j2 = j * nx + k2; 04777 04778 for (; i < nx; i += 4) { 04779 rdata[i + j2] *= -1.0f; 04780 rdata[i + j2 + 1] *= -1.0f; 04781 } 04782 } 04783 } 04784 }
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 4883 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().
04884 { 04885 int nx = image->get_xsize(); 04886 int ny = image->get_ysize(); 04887 int nz = image->get_zsize(); 04888 04889 int xodd = (nx % 2) == 1; 04890 int yodd = (ny % 2) == 1; 04891 int zodd = (nz % 2) == 1; 04892 04893 int nxy = nx * ny; 04894 04895 float *rdata = image->get_data(); 04896 04897 if ( ny == 1 && nz == 1 ){ 04898 throw ImageDimensionException("Error, cannot handle 1D images. This function should not have been called"); 04899 } 04900 else if ( nz == 1 ) { 04901 float tmp; 04902 if ( yodd ) { 04903 // Iterate along middle row, swapping values where appropriate 04904 int r = ny/2; 04905 for ( int c = 0; c < nx/2; ++c ) { 04906 int idx1 = r*nx + c; 04907 int idx2 = r*nx + c + nx/2+ xodd; 04908 tmp = rdata[idx1]; 04909 rdata[idx1] = rdata[idx2]; 04910 rdata[idx2] = tmp; 04911 } 04912 } 04913 04914 if ( xodd ) { 04915 // Iterate along the central column, swapping values where appropriate 04916 int c = nx/2; 04917 for ( int r = 0; r < ny/2; ++r ) { 04918 int idx1 = r*nx + c; 04919 int idx2 = (r+ny/2+yodd)*nx + c; 04920 tmp = rdata[idx1]; 04921 rdata[idx1] = rdata[idx2]; 04922 rdata[idx2] = tmp; 04923 } 04924 } 04925 } 04926 else // nx && ny && nz are greater than 1 04927 { 04928 float tmp; 04929 if ( xodd ) { 04930 // Iterate along the x = nx/2 slice, swapping values where appropriate 04931 int c = nx/2; 04932 size_t idx1, idx2; 04933 for( int s = 0; s < nz/2; ++s ) { 04934 for ( int r = 0; r < ny/2; ++r ) { 04935 idx1 = s*nxy+r*nx+c; 04936 idx2 = (s+nz/2+zodd)*nxy+(r+ny/2+yodd)*nx+c; 04937 tmp = rdata[idx1]; 04938 rdata[idx1] = rdata[idx2]; 04939 rdata[idx2] = tmp; 04940 } 04941 } 04942 04943 for( int s = nz-1; s >= (nz/2+zodd); --s ) { 04944 for ( int r = 0; r < ny/2; ++r ) { 04945 idx1 = s*nxy+r*nx+c; 04946 idx2 = (s-nz/2-zodd)*nxy+(r+ny/2+yodd)*nx+c; 04947 tmp = rdata[idx1]; 04948 rdata[idx1] = rdata[idx2]; 04949 rdata[idx2] = tmp; 04950 } 04951 } 04952 } 04953 if ( yodd ) { 04954 // Iterate along the y = ny/2 slice, swapping values where appropriate 04955 int r = ny/2; 04956 size_t idx1, idx2; 04957 for( int s = 0; s < nz/2; ++s ) { 04958 for ( int c = 0; c < nx/2; ++c ) { 04959 idx1 = s*nxy+r*nx+c; 04960 idx2 =(s+nz/2+zodd)*nxy+r*nx+c+nx/2+xodd; 04961 tmp = rdata[idx1]; 04962 rdata[idx1] = rdata[idx2]; 04963 rdata[idx2] = tmp; 04964 } 04965 } 04966 04967 for( int s = nz-1; s >= (nz/2+zodd); --s ) { 04968 for ( int c = 0; c < nx/2; ++c ) { 04969 idx1 = s*nxy+r*nx+c; 04970 idx2 = (s-nz/2-zodd)*nxy+r*nx+c+nx/2+xodd; 04971 tmp = rdata[idx1]; 04972 rdata[idx1] = rdata[idx2]; 04973 rdata[idx2] = tmp; 04974 } 04975 } 04976 } 04977 if ( zodd ) { 04978 // Iterate along the z = nz/2 slice, swapping values where appropriate 04979 int s = nz/2; 04980 size_t idx1, idx2; 04981 for( int r = 0; r < ny/2; ++r ) { 04982 for ( int c = 0; c < nx/2; ++c ) { 04983 idx1 = s*nxy+r*nx+c; 04984 idx2 = s*nxy+(r+ny/2+yodd)*nx+c+nx/2+xodd; 04985 tmp = rdata[idx1]; 04986 rdata[idx1] = rdata[idx2]; 04987 rdata[idx2] = tmp; 04988 } 04989 } 04990 04991 for( int r = ny-1; r >= (ny/2+yodd); --r ) { 04992 for ( int c = 0; c < nx/2; ++c ) { 04993 idx1 = s*nxy+r*nx+c; 04994 idx2 = s*nxy+(r-ny/2-yodd)*nx+c+nx/2+xodd; 04995 tmp = rdata[idx1]; 04996 rdata[idx1] = rdata[idx2]; 04997 rdata[idx2] = tmp; 04998 } 04999 } 05000 } 05001 } 05002 }
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 4786 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().
04787 { 04788 int nx = image->get_xsize(); 04789 int ny = image->get_ysize(); 04790 int nz = image->get_zsize(); 04791 04792 int xodd = (nx % 2) == 1; 04793 int yodd = (ny % 2) == 1; 04794 int zodd = (nz % 2) == 1; 04795 04796 int nxy = nx * ny; 04797 04798 float *rdata = image->get_data(); 04799 04800 if ( ny == 1 && nz == 1 ){ 04801 throw ImageDimensionException("Error, cannot handle 1D images. This function should not have been called"); 04802 } 04803 else if ( nz == 1 ) { 04804 04805 // Swap the bottom left and top right corners 04806 for ( int r = 0; r < ny/2; ++r ) { 04807 for ( int c = 0; c < nx/2; ++c) { 04808 int idx1 = r*nx + c; 04809 int idx2 = (r+ny/2+yodd)*nx + c + nx/2+xodd; 04810 float tmp = rdata[idx1]; 04811 rdata[idx1] = rdata[idx2]; 04812 rdata[idx2] = tmp; 04813 } 04814 } 04815 04816 // Swap the top left and bottom right corners 04817 for ( int r = ny-1; r >= (ny/2+yodd); --r ) { 04818 for ( int c = 0; c < nx/2; ++c) { 04819 int idx1 = r*nx + c; 04820 int idx2 = (r-ny/2-yodd)*nx + c + nx/2+xodd; 04821 float tmp = rdata[idx1]; 04822 rdata[idx1] = rdata[idx2]; 04823 rdata[idx2] = tmp; 04824 } 04825 } 04826 } 04827 else // nx && ny && nz are greater than 1 04828 { 04829 float tmp; 04830 // Swap the bottom left front and back right top quadrants 04831 size_t idx1, idx2; 04832 04833 for ( int s = 0; s < nz/2; ++s ) { 04834 for ( int r = 0; r < ny/2; ++r ) { 04835 for ( int c = 0; c < nx/2; ++ c) { 04836 idx1 = s*nxy+r*nx+c; 04837 idx2 = (s+nz/2+zodd)*nxy+(r+ny/2+yodd)*nx+c+nx/2+xodd; 04838 tmp = rdata[idx1]; 04839 rdata[idx1] = rdata[idx2]; 04840 rdata[idx2] = tmp; 04841 } 04842 } 04843 } 04844 // Swap the bottom right front and back left top quadrants 04845 for ( int s = 0; s < nz/2; ++s ) { 04846 for ( int r = 0; r < ny/2; ++r ) { 04847 for ( int c = nx-1; c >= (nx/2+xodd); --c) { 04848 idx1 = s*nxy+r*nx+c; 04849 idx2 = (s+nz/2+zodd)*nxy+(r+ny/2+yodd)*nx+c-nx/2-xodd; 04850 tmp = rdata[idx1]; 04851 rdata[idx1] = rdata[idx2]; 04852 rdata[idx2] = tmp; 04853 } 04854 } 04855 } 04856 // Swap the top right front and back left bottom quadrants 04857 for ( int s = 0; s < nz/2; ++s ) { 04858 for ( int r = ny-1; r >= (ny/2+yodd); --r ) { 04859 for ( int c = nx-1; c >= (nx/2+xodd); --c) { 04860 idx1 = s*nxy+r*nx+c; 04861 idx2 = (s+nz/2+zodd)*nxy+(r-ny/2-yodd)*nx+c-nx/2-xodd; 04862 tmp = rdata[idx1]; 04863 rdata[idx1] = rdata[idx2]; 04864 rdata[idx2] = tmp; 04865 } 04866 } 04867 } 04868 // Swap the top left front and back right bottom quadrants 04869 for ( int s = 0; s < nz/2; ++s ) { 04870 for ( int r = ny-1; r >= (ny/2+yodd); --r ) { 04871 for ( int c = 0; c < nx/2; ++c) { 04872 idx1 = s*nxy+r*nx+c; 04873 idx2 = (s+nz/2+zodd)*nxy+(r-ny/2-yodd)*nx+c+nx/2+xodd; 04874 tmp = rdata[idx1]; 04875 rdata[idx1] = rdata[idx2]; 04876 rdata[idx2] = tmp; 04877 } 04878 } 04879 } 04880 } 04881 }