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