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