#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 4830 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 4791 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().
04792 { 04793 if ( !image->is_complex() ) throw ImageFormatException("Can not handle images that are not complex in fourier phase shift 180"); 04794 04795 int nx = image->get_xsize(); 04796 int ny = image->get_ysize(); 04797 int nz = image->get_zsize(); 04798 04799 int nxy = nx * ny; 04800 04801 float *rdata = image->get_data(); 04802 04803 // Who uses this function? It doesn't work for odd images, and it will give incorrect results for some even images 04804 // d.woolford, March 15 2009 04805 int of=0; 04806 if (((ny/2)%2)+((nz/2)%2)==1) of=1; 04807 04808 for (int k = 0; k < nz; k++) { 04809 size_t k2 = (size_t)k * nxy; 04810 04811 for (int j = 0; j < ny; j++) { 04812 int i = ((k+j)%2==of?2:0); 04813 size_t j2 = j * nx + k2; 04814 04815 for (; i < nx; i += 4) { 04816 rdata[i + j2] *= -1.0f; 04817 rdata[i + j2 + 1] *= -1.0f; 04818 } 04819 } 04820 } 04821 }
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 4920 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().
04921 { 04922 int nx = image->get_xsize(); 04923 int ny = image->get_ysize(); 04924 int nz = image->get_zsize(); 04925 04926 int xodd = (nx % 2) == 1; 04927 int yodd = (ny % 2) == 1; 04928 int zodd = (nz % 2) == 1; 04929 04930 int nxy = nx * ny; 04931 04932 float *rdata = image->get_data(); 04933 04934 if ( ny == 1 && nz == 1 ){ 04935 throw ImageDimensionException("Error, cannot handle 1D images. This function should not have been called"); 04936 } 04937 else if ( nz == 1 ) { 04938 float tmp; 04939 if ( yodd ) { 04940 // Iterate along middle row, swapping values where appropriate 04941 int r = ny/2; 04942 for ( int c = 0; c < nx/2; ++c ) { 04943 int idx1 = r*nx + c; 04944 int idx2 = r*nx + c + nx/2+ xodd; 04945 tmp = rdata[idx1]; 04946 rdata[idx1] = rdata[idx2]; 04947 rdata[idx2] = tmp; 04948 } 04949 } 04950 04951 if ( xodd ) { 04952 // Iterate along the central column, swapping values where appropriate 04953 int c = nx/2; 04954 for ( int r = 0; r < ny/2; ++r ) { 04955 int idx1 = r*nx + c; 04956 int idx2 = (r+ny/2+yodd)*nx + c; 04957 tmp = rdata[idx1]; 04958 rdata[idx1] = rdata[idx2]; 04959 rdata[idx2] = tmp; 04960 } 04961 } 04962 } 04963 else // nx && ny && nz are greater than 1 04964 { 04965 float tmp; 04966 if ( xodd ) { 04967 // Iterate along the x = nx/2 slice, swapping values where appropriate 04968 int c = nx/2; 04969 size_t idx1, idx2; 04970 for( int s = 0; s < nz/2; ++s ) { 04971 for ( int r = 0; r < ny/2; ++r ) { 04972 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04973 idx2 = (s+nz/2+zodd)*(size_t)nxy+(r+ny/2+yodd)*(size_t)nx+c; 04974 tmp = rdata[idx1]; 04975 rdata[idx1] = rdata[idx2]; 04976 rdata[idx2] = tmp; 04977 } 04978 } 04979 04980 for( int s = nz-1; s >= (nz/2+zodd); --s ) { 04981 for ( int r = 0; r < ny/2; ++r ) { 04982 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04983 idx2 = (s-nz/2-zodd)*(size_t)nxy+(r+ny/2+yodd)*(size_t)nx+c; 04984 tmp = rdata[idx1]; 04985 rdata[idx1] = rdata[idx2]; 04986 rdata[idx2] = tmp; 04987 } 04988 } 04989 } 04990 if ( yodd ) { 04991 // Iterate along the y = ny/2 slice, swapping values where appropriate 04992 int r = ny/2; 04993 size_t idx1, idx2; 04994 for( int s = 0; s < nz/2; ++s ) { 04995 for ( int c = 0; c < nx/2; ++c ) { 04996 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04997 idx2 =(s+nz/2+zodd)*(size_t)nxy+(size_t)r*nx+c+nx/2+xodd; 04998 tmp = rdata[idx1]; 04999 rdata[idx1] = rdata[idx2]; 05000 rdata[idx2] = tmp; 05001 } 05002 } 05003 05004 for( int s = nz-1; s >= (nz/2+zodd); --s ) { 05005 for ( int c = 0; c < nx/2; ++c ) { 05006 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 05007 idx2 = (s-nz/2-zodd)*(size_t)nxy+(size_t)r*nx+c+nx/2+xodd; 05008 tmp = rdata[idx1]; 05009 rdata[idx1] = rdata[idx2]; 05010 rdata[idx2] = tmp; 05011 } 05012 } 05013 } 05014 if ( zodd ) { 05015 // Iterate along the z = nz/2 slice, swapping values where appropriate 05016 int s = nz/2; 05017 size_t idx1, idx2; 05018 for( int r = 0; r < ny/2; ++r ) { 05019 for ( int c = 0; c < nx/2; ++c ) { 05020 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 05021 idx2 = (size_t)s*nxy+(r+ny/2+yodd)*(size_t)nx+c+nx/2+xodd; 05022 tmp = rdata[idx1]; 05023 rdata[idx1] = rdata[idx2]; 05024 rdata[idx2] = tmp; 05025 } 05026 } 05027 05028 for( int r = ny-1; r >= (ny/2+yodd); --r ) { 05029 for ( int c = 0; c < nx/2; ++c ) { 05030 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 05031 idx2 = (size_t)s*nxy+(r-ny/2-yodd)*(size_t)nx+c+nx/2+xodd; 05032 tmp = rdata[idx1]; 05033 rdata[idx1] = rdata[idx2]; 05034 rdata[idx2] = tmp; 05035 } 05036 } 05037 } 05038 } 05039 }
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 4823 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().
04824 { 04825 int nx = image->get_xsize(); 04826 int ny = image->get_ysize(); 04827 int nz = image->get_zsize(); 04828 04829 int xodd = (nx % 2) == 1; 04830 int yodd = (ny % 2) == 1; 04831 int zodd = (nz % 2) == 1; 04832 04833 int nxy = nx * ny; 04834 04835 float *rdata = image->get_data(); 04836 04837 if ( ny == 1 && nz == 1 ){ 04838 throw ImageDimensionException("Error, cannot handle 1D images. This function should not have been called"); 04839 } 04840 else if ( nz == 1 ) { 04841 04842 // Swap the bottom left and top right corners 04843 for ( int r = 0; r < ny/2; ++r ) { 04844 for ( int c = 0; c < nx/2; ++c) { 04845 int idx1 = r*nx + c; 04846 int idx2 = (r+ny/2+yodd)*nx + c + nx/2+xodd; 04847 float tmp = rdata[idx1]; 04848 rdata[idx1] = rdata[idx2]; 04849 rdata[idx2] = tmp; 04850 } 04851 } 04852 04853 // Swap the top left and bottom right corners 04854 for ( int r = ny-1; r >= (ny/2+yodd); --r ) { 04855 for ( int c = 0; c < nx/2; ++c) { 04856 int idx1 = r*nx + c; 04857 int idx2 = (r-ny/2-yodd)*nx + c + nx/2+xodd; 04858 float tmp = rdata[idx1]; 04859 rdata[idx1] = rdata[idx2]; 04860 rdata[idx2] = tmp; 04861 } 04862 } 04863 } 04864 else // nx && ny && nz are greater than 1 04865 { 04866 float tmp; 04867 // Swap the bottom left front and back right top quadrants 04868 size_t idx1, idx2; 04869 04870 for ( int s = 0; s < nz/2; ++s ) { 04871 for ( int r = 0; r < ny/2; ++r ) { 04872 for ( int c = 0; c < nx/2; ++ c) { 04873 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04874 idx2 = (s+nz/2+zodd)*(size_t)nxy+(r+ny/2+yodd)*(size_t)nx+c+nx/2+xodd; 04875 tmp = rdata[idx1]; 04876 rdata[idx1] = rdata[idx2]; 04877 rdata[idx2] = tmp; 04878 } 04879 } 04880 } 04881 // Swap the bottom right front and back left top quadrants 04882 for ( int s = 0; s < nz/2; ++s ) { 04883 for ( int r = 0; r < ny/2; ++r ) { 04884 for ( int c = nx-1; c >= (nx/2+xodd); --c) { 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-nx/2-xodd; 04887 tmp = rdata[idx1]; 04888 rdata[idx1] = rdata[idx2]; 04889 rdata[idx2] = tmp; 04890 } 04891 } 04892 } 04893 // Swap the top right front and back left bottom quadrants 04894 for ( int s = 0; s < nz/2; ++s ) { 04895 for ( int r = ny-1; r >= (ny/2+yodd); --r ) { 04896 for ( int c = nx-1; c >= (nx/2+xodd); --c) { 04897 idx1 = (size_t)s*nxy+(size_t)r*nx+c; 04898 idx2 = (s+nz/2+zodd)*(size_t)nxy+(r-ny/2-yodd)*(size_t)nx+c-nx/2-xodd; 04899 tmp = rdata[idx1]; 04900 rdata[idx1] = rdata[idx2]; 04901 rdata[idx2] = tmp; 04902 } 04903 } 04904 } 04905 // Swap the top left front and back right bottom quadrants 04906 for ( int s = 0; s < nz/2; ++s ) { 04907 for ( int r = ny-1; r >= (ny/2+yodd); --r ) { 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+(r-ny/2-yodd)*(size_t)nx+c+nx/2+xodd; 04911 tmp = rdata[idx1]; 04912 rdata[idx1] = rdata[idx2]; 04913 rdata[idx2] = tmp; 04914 } 04915 } 04916 } 04917 } 04918 }