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