#include <processor.h>


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 4690 of file processor.h.
| 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 4585 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().
04586 { 04587 int nx = image->get_xsize(); 04588 int ny = image->get_ysize(); 04589 int nz = image->get_zsize(); 04590 04591 int xodd = (nx % 2) == 1; 04592 int yodd = (ny % 2) == 1; 04593 int zodd = (nz % 2) == 1; 04594 04595 int nxy = nx * ny; 04596 04597 float *rdata = image->get_data(); 04598 04599 if ( ny == 1 && nz == 1 ){ 04600 throw ImageDimensionException("Error, cannot handle 1D images. This function should not have been called"); 04601 } 04602 else if ( nz == 1 ) { 04603 04604 // Swap the bottom left and top right corners 04605 for ( int r = 0; r < ny/2; ++r ) { 04606 for ( int c = 0; c < nx/2; ++c) { 04607 int idx1 = r*nx + c; 04608 int idx2 = (r+ny/2+yodd)*nx + c + nx/2+xodd; 04609 float tmp = rdata[idx1]; 04610 rdata[idx1] = rdata[idx2]; 04611 rdata[idx2] = tmp; 04612 } 04613 } 04614 04615 // Swap the top left and bottom right corners 04616 for ( int r = ny-1; r >= (ny/2+yodd); --r ) { 04617 for ( int c = 0; c < nx/2; ++c) { 04618 int idx1 = r*nx + c; 04619 int idx2 = (r-ny/2-yodd)*nx + c + nx/2+xodd; 04620 float tmp = rdata[idx1]; 04621 rdata[idx1] = rdata[idx2]; 04622 rdata[idx2] = tmp; 04623 } 04624 } 04625 } 04626 else // nx && ny && nz are greater than 1 04627 { 04628 float tmp; 04629 // Swap the bottom left front and back right top quadrants 04630 size_t idx1, idx2; 04631 04632 for ( int s = 0; s < nz/2; ++s ) { 04633 for ( int r = 0; r < ny/2; ++r ) { 04634 for ( int c = 0; c < nx/2; ++ c) { 04635 idx1 = s*nxy+r*nx+c; 04636 idx2 = (s+nz/2+zodd)*nxy+(r+ny/2+yodd)*nx+c+nx/2+xodd; 04637 tmp = rdata[idx1]; 04638 rdata[idx1] = rdata[idx2]; 04639 rdata[idx2] = tmp; 04640 } 04641 } 04642 } 04643 // Swap the bottom right front and back left top quadrants 04644 for ( int s = 0; s < nz/2; ++s ) { 04645 for ( int r = 0; r < ny/2; ++r ) { 04646 for ( int c = nx-1; c >= (nx/2+xodd); --c) { 04647 idx1 = s*nxy+r*nx+c; 04648 idx2 = (s+nz/2+zodd)*nxy+(r+ny/2+yodd)*nx+c-nx/2-xodd; 04649 tmp = rdata[idx1]; 04650 rdata[idx1] = rdata[idx2]; 04651 rdata[idx2] = tmp; 04652 } 04653 } 04654 } 04655 // Swap the top right front and back left bottom quadrants 04656 for ( int s = 0; s < nz/2; ++s ) { 04657 for ( int r = ny-1; r >= (ny/2+yodd); --r ) { 04658 for ( int c = nx-1; c >= (nx/2+xodd); --c) { 04659 idx1 = s*nxy+r*nx+c; 04660 idx2 = (s+nz/2+zodd)*nxy+(r-ny/2-yodd)*nx+c-nx/2-xodd; 04661 tmp = rdata[idx1]; 04662 rdata[idx1] = rdata[idx2]; 04663 rdata[idx2] = tmp; 04664 } 04665 } 04666 } 04667 // Swap the top left front and back right bottom quadrants 04668 for ( int s = 0; s < nz/2; ++s ) { 04669 for ( int r = ny-1; r >= (ny/2+yodd); --r ) { 04670 for ( int c = 0; c < nx/2; ++c) { 04671 idx1 = s*nxy+r*nx+c; 04672 idx2 = (s+nz/2+zodd)*nxy+(r-ny/2-yodd)*nx+c+nx/2+xodd; 04673 tmp = rdata[idx1]; 04674 rdata[idx1] = rdata[idx2]; 04675 rdata[idx2] = tmp; 04676 } 04677 } 04678 } 04679 } 04680 }
| 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 4682 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().
04683 { 04684 int nx = image->get_xsize(); 04685 int ny = image->get_ysize(); 04686 int nz = image->get_zsize(); 04687 04688 int xodd = (nx % 2) == 1; 04689 int yodd = (ny % 2) == 1; 04690 int zodd = (nz % 2) == 1; 04691 04692 int nxy = nx * ny; 04693 04694 float *rdata = image->get_data(); 04695 04696 if ( ny == 1 && nz == 1 ){ 04697 throw ImageDimensionException("Error, cannot handle 1D images. This function should not have been called"); 04698 } 04699 else if ( nz == 1 ) { 04700 float tmp; 04701 if ( yodd ) { 04702 // Iterate along middle row, swapping values where appropriate 04703 int r = ny/2; 04704 for ( int c = 0; c < nx/2; ++c ) { 04705 int idx1 = r*nx + c; 04706 int idx2 = r*nx + c + nx/2+ xodd; 04707 tmp = rdata[idx1]; 04708 rdata[idx1] = rdata[idx2]; 04709 rdata[idx2] = tmp; 04710 } 04711 } 04712 04713 if ( xodd ) { 04714 // Iterate along the central column, swapping values where appropriate 04715 int c = nx/2; 04716 for ( int r = 0; r < ny/2; ++r ) { 04717 int idx1 = r*nx + c; 04718 int idx2 = (r+ny/2+yodd)*nx + c; 04719 tmp = rdata[idx1]; 04720 rdata[idx1] = rdata[idx2]; 04721 rdata[idx2] = tmp; 04722 } 04723 } 04724 } 04725 else // nx && ny && nz are greater than 1 04726 { 04727 float tmp; 04728 if ( xodd ) { 04729 // Iterate along the x = nx/2 slice, swapping values where appropriate 04730 int c = nx/2; 04731 size_t idx1, idx2; 04732 for( int s = 0; s < nz/2; ++s ) { 04733 for ( int r = 0; r < ny/2; ++r ) { 04734 idx1 = s*nxy+r*nx+c; 04735 idx2 = (s+nz/2+zodd)*nxy+(r+ny/2+yodd)*nx+c; 04736 tmp = rdata[idx1]; 04737 rdata[idx1] = rdata[idx2]; 04738 rdata[idx2] = tmp; 04739 } 04740 } 04741 04742 for( int s = nz-1; s >= (nz/2+zodd); --s ) { 04743 for ( int r = 0; r < ny/2; ++r ) { 04744 idx1 = s*nxy+r*nx+c; 04745 idx2 = (s-nz/2-zodd)*nxy+(r+ny/2+yodd)*nx+c; 04746 tmp = rdata[idx1]; 04747 rdata[idx1] = rdata[idx2]; 04748 rdata[idx2] = tmp; 04749 } 04750 } 04751 } 04752 if ( yodd ) { 04753 // Iterate along the y = ny/2 slice, swapping values where appropriate 04754 int r = ny/2; 04755 size_t idx1, idx2; 04756 for( int s = 0; s < nz/2; ++s ) { 04757 for ( int c = 0; c < nx/2; ++c ) { 04758 idx1 = s*nxy+r*nx+c; 04759 idx2 =(s+nz/2+zodd)*nxy+r*nx+c+nx/2+xodd; 04760 tmp = rdata[idx1]; 04761 rdata[idx1] = rdata[idx2]; 04762 rdata[idx2] = tmp; 04763 } 04764 } 04765 04766 for( int s = nz-1; s >= (nz/2+zodd); --s ) { 04767 for ( int c = 0; c < nx/2; ++c ) { 04768 idx1 = s*nxy+r*nx+c; 04769 idx2 = (s-nz/2-zodd)*nxy+r*nx+c+nx/2+xodd; 04770 tmp = rdata[idx1]; 04771 rdata[idx1] = rdata[idx2]; 04772 rdata[idx2] = tmp; 04773 } 04774 } 04775 } 04776 if ( zodd ) { 04777 // Iterate along the z = nz/2 slice, swapping values where appropriate 04778 int s = nz/2; 04779 size_t idx1, idx2; 04780 for( int r = 0; r < ny/2; ++r ) { 04781 for ( int c = 0; c < nx/2; ++c ) { 04782 idx1 = s*nxy+r*nx+c; 04783 idx2 = s*nxy+(r+ny/2+yodd)*nx+c+nx/2+xodd; 04784 tmp = rdata[idx1]; 04785 rdata[idx1] = rdata[idx2]; 04786 rdata[idx2] = tmp; 04787 } 04788 } 04789 04790 for( int r = ny-1; r >= (ny/2+yodd); --r ) { 04791 for ( int c = 0; c < nx/2; ++c ) { 04792 idx1 = s*nxy+r*nx+c; 04793 idx2 = s*nxy+(r-ny/2-yodd)*nx+c+nx/2+xodd; 04794 tmp = rdata[idx1]; 04795 rdata[idx1] = rdata[idx2]; 04796 rdata[idx2] = tmp; 04797 } 04798 } 04799 } 04800 } 04801 }
| 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 4553 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().
04554 { 04555 if ( !image->is_complex() ) throw ImageFormatException("Can not handle images that are not complex in fourier phase shift 180"); 04556 04557 int nx = image->get_xsize(); 04558 int ny = image->get_ysize(); 04559 int nz = image->get_zsize(); 04560 04561 int nxy = nx * ny; 04562 04563 float *rdata = image->get_data(); 04564 04565 // Who uses this function? It doesn't work for odd images, and it will give incorrect results for some even images 04566 // d.woolford, March 15 2009 04567 int of=0; 04568 if (((ny/2)%2)+((nz/2)%2)==1) of=1; 04569 04570 for (int k = 0; k < nz; k++) { 04571 size_t k2 = k * nxy; 04572 04573 for (int j = 0; j < ny; j++) { 04574 int i = ((k+j)%2==of?2:0); 04575 size_t j2 = j * nx + k2; 04576 04577 for (; i < nx; i += 4) { 04578 rdata[i + j2] *= -1.0f; 04579 rdata[i + j2 + 1] *= -1.0f; 04580 } 04581 } 04582 } 04583 }
1.5.6