#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 4785 of file processor.h.
|
fourier_phaseshift180 - fourier phase shift by 180 this function is called internally if the argument to the process_inplace function is complex.
Definition at line 4719 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(), nx, ny, and rdata. Referenced by EMAN::PhaseToCenterProcessor::process_inplace(), and EMAN::PhaseToCornerProcessor::process_inplace(). 04720 { 04721 if ( !image->is_complex() ) throw ImageFormatException("Can not handle images that are not complex in fourier phase shift 180"); 04722 04723 int nx = image->get_xsize(); 04724 int ny = image->get_ysize(); 04725 int nz = image->get_zsize(); 04726 04727 int nxy = nx * ny; 04728 04729 float *rdata = image->get_data(); 04730 04731 // Who uses this function? It doesn't work for odd images, and it will give incorrect results for some even images 04732 // d.woolford, March 15 2009 04733 int of=0; 04734 if (((ny/2)%2)+((nz/2)%2)==1) of=1; 04735 04736 for (int k = 0; k < nz; k++) { 04737 size_t k2 = (size_t)k * nxy; 04738 04739 for (int j = 0; j < ny; j++) { 04740 int i = ((k+j)%2==of?2:0); 04741 size_t j2 = j * nx + k2; 04742 04743 for (; i < nx; i += 4) { 04744 rdata[i + j2] *= -1.0f; 04745 rdata[i + j2 + 1] *= -1.0f; 04746 } 04747 } 04748 } 04749 }
|
|
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
Definition at line 4848 of file processor.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, nx, ny, and rdata. Referenced by EMAN::PhaseToCenterProcessor::process_inplace(), and EMAN::PhaseToCornerProcessor::process_inplace(). 04849 { 04850 int nx = image->get_xsize(); 04851 int ny = image->get_ysize(); 04852 int nz = image->get_zsize(); 04853 04854 int xodd = (nx % 2) == 1; 04855 int yodd = (ny % 2) == 1; 04856 int zodd = (nz % 2) == 1; 04857 04858 int nxy = nx * ny; 04859 04860 float *rdata = image->get_data(); 04861 04862 if ( ny == 1 && nz == 1 ){ 04863 throw ImageDimensionException("Error, cannot handle 1D images. This function should not have been called"); 04864 } 04865 else if ( nz == 1 ) { 04866 float tmp; 04867 if ( yodd ) { 04868 // Iterate along middle row, swapping values where appropriate 04869 int r = ny/2; 04870 for ( int c = 0; c < nx/2; ++c ) { 04871 int idx1 = r*nx + c; 04872 int idx2 = r*nx + c + nx/2+ xodd; 04873 tmp = rdata[idx1]; 04874 rdata[idx1] = rdata[idx2]; 04875 rdata[idx2] = tmp; 04876 } 04877 } 04878 04879 if ( xodd ) { 04880 // Iterate along the central column, swapping values where appropriate 04881 int c = nx/2; 04882 for ( int r = 0; r < ny/2; ++r ) { 04883 int idx1 = r*nx + c; 04884 int idx2 = (r+ny/2+yodd)*nx + c; 04885 tmp = rdata[idx1]; 04886 rdata[idx1] = rdata[idx2]; 04887 rdata[idx2] = tmp; 04888 } 04889 } 04890 } 04891 else // nx && ny && nz are greater than 1 04892 { 04893 float tmp; 04894 if ( xodd ) { 04895 // Iterate along the x = nx/2 slice, swapping values where appropriate 04896 int c = nx/2; 04897 size_t idx1, idx2; 04898 for( int s = 0; s < nz/2; ++s ) { 04899 for ( int r = 0; r < ny/2; ++r ) { 04900 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04901 idx2 = (s+nz/2+zodd)*(size_t)nxy+(r+ny/2+yodd)*(size_t)nx+c; 04902 tmp = rdata[idx1]; 04903 rdata[idx1] = rdata[idx2]; 04904 rdata[idx2] = tmp; 04905 } 04906 } 04907 04908 for( int s = nz-1; s >= (nz/2+zodd); --s ) { 04909 for ( int r = 0; r < ny/2; ++r ) { 04910 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04911 idx2 = (s-nz/2-zodd)*(size_t)nxy+(r+ny/2+yodd)*(size_t)nx+c; 04912 tmp = rdata[idx1]; 04913 rdata[idx1] = rdata[idx2]; 04914 rdata[idx2] = tmp; 04915 } 04916 } 04917 } 04918 if ( yodd ) { 04919 // Iterate along the y = ny/2 slice, swapping values where appropriate 04920 int r = ny/2; 04921 size_t idx1, idx2; 04922 for( int s = 0; s < nz/2; ++s ) { 04923 for ( int c = 0; c < nx/2; ++c ) { 04924 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04925 idx2 =(s+nz/2+zodd)*(size_t)nxy+(size_t)r*nx+c+nx/2+xodd; 04926 tmp = rdata[idx1]; 04927 rdata[idx1] = rdata[idx2]; 04928 rdata[idx2] = tmp; 04929 } 04930 } 04931 04932 for( int s = nz-1; s >= (nz/2+zodd); --s ) { 04933 for ( int c = 0; c < nx/2; ++c ) { 04934 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04935 idx2 = (s-nz/2-zodd)*(size_t)nxy+(size_t)r*nx+c+nx/2+xodd; 04936 tmp = rdata[idx1]; 04937 rdata[idx1] = rdata[idx2]; 04938 rdata[idx2] = tmp; 04939 } 04940 } 04941 } 04942 if ( zodd ) { 04943 // Iterate along the z = nz/2 slice, swapping values where appropriate 04944 int s = nz/2; 04945 size_t idx1, idx2; 04946 for( int r = 0; r < ny/2; ++r ) { 04947 for ( int c = 0; c < nx/2; ++c ) { 04948 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04949 idx2 = (size_t)s*nxy+(r+ny/2+yodd)*(size_t)nx+c+nx/2+xodd; 04950 tmp = rdata[idx1]; 04951 rdata[idx1] = rdata[idx2]; 04952 rdata[idx2] = tmp; 04953 } 04954 } 04955 04956 for( int r = ny-1; r >= (ny/2+yodd); --r ) { 04957 for ( int c = 0; c < nx/2; ++c ) { 04958 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04959 idx2 = (size_t)s*nxy+(r-ny/2-yodd)*(size_t)nx+c+nx/2+xodd; 04960 tmp = rdata[idx1]; 04961 rdata[idx1] = rdata[idx2]; 04962 rdata[idx2] = tmp; 04963 } 04964 } 04965 } 04966 } 04967 }
|
|
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
Definition at line 4751 of file processor.cpp. References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ImageDimensionException, nx, ny, and rdata. Referenced by EMAN::PhaseToCenterProcessor::process_inplace(), and EMAN::PhaseToCornerProcessor::process_inplace(). 04752 { 04753 int nx = image->get_xsize(); 04754 int ny = image->get_ysize(); 04755 int nz = image->get_zsize(); 04756 04757 int xodd = (nx % 2) == 1; 04758 int yodd = (ny % 2) == 1; 04759 int zodd = (nz % 2) == 1; 04760 04761 int nxy = nx * ny; 04762 04763 float *rdata = image->get_data(); 04764 04765 if ( ny == 1 && nz == 1 ){ 04766 throw ImageDimensionException("Error, cannot handle 1D images. This function should not have been called"); 04767 } 04768 else if ( nz == 1 ) { 04769 04770 // Swap the bottom left and top right corners 04771 for ( int r = 0; r < ny/2; ++r ) { 04772 for ( int c = 0; c < nx/2; ++c) { 04773 int idx1 = r*nx + c; 04774 int idx2 = (r+ny/2+yodd)*nx + c + nx/2+xodd; 04775 float tmp = rdata[idx1]; 04776 rdata[idx1] = rdata[idx2]; 04777 rdata[idx2] = tmp; 04778 } 04779 } 04780 04781 // Swap the top left and bottom right corners 04782 for ( int r = ny-1; r >= (ny/2+yodd); --r ) { 04783 for ( int c = 0; c < nx/2; ++c) { 04784 int idx1 = r*nx + c; 04785 int idx2 = (r-ny/2-yodd)*nx + c + nx/2+xodd; 04786 float tmp = rdata[idx1]; 04787 rdata[idx1] = rdata[idx2]; 04788 rdata[idx2] = tmp; 04789 } 04790 } 04791 } 04792 else // nx && ny && nz are greater than 1 04793 { 04794 float tmp; 04795 // Swap the bottom left front and back right top quadrants 04796 size_t idx1, idx2; 04797 04798 for ( int s = 0; s < nz/2; ++s ) { 04799 for ( int r = 0; r < ny/2; ++r ) { 04800 for ( int c = 0; c < nx/2; ++ c) { 04801 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04802 idx2 = (s+nz/2+zodd)*(size_t)nxy+(r+ny/2+yodd)*(size_t)nx+c+nx/2+xodd; 04803 tmp = rdata[idx1]; 04804 rdata[idx1] = rdata[idx2]; 04805 rdata[idx2] = tmp; 04806 } 04807 } 04808 } 04809 // Swap the bottom right front and back left top quadrants 04810 for ( int s = 0; s < nz/2; ++s ) { 04811 for ( int r = 0; r < ny/2; ++r ) { 04812 for ( int c = nx-1; c >= (nx/2+xodd); --c) { 04813 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04814 idx2 = (s+nz/2+zodd)*(size_t)nxy+(r+ny/2+yodd)*(size_t)nx+c-nx/2-xodd; 04815 tmp = rdata[idx1]; 04816 rdata[idx1] = rdata[idx2]; 04817 rdata[idx2] = tmp; 04818 } 04819 } 04820 } 04821 // Swap the top right front and back left bottom quadrants 04822 for ( int s = 0; s < nz/2; ++s ) { 04823 for ( int r = ny-1; r >= (ny/2+yodd); --r ) { 04824 for ( int c = nx-1; c >= (nx/2+xodd); --c) { 04825 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04826 idx2 = (s+nz/2+zodd)*(size_t)nxy+(r-ny/2-yodd)*(size_t)nx+c-nx/2-xodd; 04827 tmp = rdata[idx1]; 04828 rdata[idx1] = rdata[idx2]; 04829 rdata[idx2] = tmp; 04830 } 04831 } 04832 } 04833 // Swap the top left front and back right bottom quadrants 04834 for ( int s = 0; s < nz/2; ++s ) { 04835 for ( int r = ny-1; r >= (ny/2+yodd); --r ) { 04836 for ( int c = 0; c < nx/2; ++c) { 04837 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04838 idx2 = (s+nz/2+zodd)*(size_t)nxy+(r-ny/2-yodd)*(size_t)nx+c+nx/2+xodd; 04839 tmp = rdata[idx1]; 04840 rdata[idx1] = rdata[idx2]; 04841 rdata[idx2] = tmp; 04842 } 04843 } 04844 } 04845 } 04846 }
|