




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Paper; Class: INTRO TO MATH MODELING; Subject: Mathematics; University: San Diego State University; Term: Unknown 1989;
Typology: Papers
1 / 8
This page cannot be seen from the preview
Don't miss anything!
Figure 1: (Left) A 15 × 15 regular square-lattice in two dimen-
sions. The so-called lattice sites are located at the interestion points
of the grid lines. Associated with eace lattice site is a single spin
variable. When the interactions between spins on the lattice are
first-order nearest-neighbor interactions, the grid lines connecting
the lattice sites accurately depict this interaction scheme across the
entire lattice. (Right) First-order nearest-neighbor interactions in
two dimensions. A spin, centrally located on a lattice site, is cou-
pled only to it’s nearest horizontal and vertical neighbors.
The total energy of the spin-lattice for a given configuration of spins
is defined by
E = −
∑
μij Hij Sij −
∑
JijklSij Skl, (1)
where μij is a coupling constant that sets the interaction strength
between an individual spin and an externally applied magnetic field,
Hij , that may be acting on the system. Jijkl is a coupling constant
that sets the interaction strengths between locally coupled spins.
The brackets 〈〉 over the sum of spin-spin interactions is used to
designate that it extends only over nearest-neighbor pairs of spins.
For each pair of spins, if Jijkl > 0 , then the spin-spin interaction is
called ferromagnetic. If Jijkl < 0 , the interaction is referred to as
antiferromagnetic. When Jijkl = 0, there is no interaction between
the two spins.
In the context of statistical mechanics, the principal problem that
must be solved for the Ising model is to find the ground state spin-
lattice configuration, i.e. to find the lowest energy configuration of
the lattice at a specific inverse lattice temperature, β, given some
initial spin-lattice configuration {Sij }, the sets of coupling con-
stants {μij } and {Jijkl}, and an externally applied magnetic field
{Hij }. Notice that when the interactions between two spins are fer-
romagnetic, it is energetically favorable for the spins to be aligned
with one another. In fact, when all of the spin-spin interactions in
the lattice are ferromagnetic, we find that above a certain critical in-
verse lattice temperature, βc, the spin-lattice undergoes a so-called
phase transition. Here, the ground state spin-lattice stablizes and
large, locally connected regions of the lattice begin to align with one
another due to collective interactions arising from the long range
correlations between the spins. In the absence of an externally ap-
plied magnetic field, i.e. {Hij = 0}, this cooperative phenomenon
is known as spontaneous magnetization. Hoever, more importantly,
this collective alignment of different regions of the lattice is the pre-
cise property we aim to exploit in the binary and grayscale image
restoration process. Thus, we expect to the image restoration pro-
cess to occur for inverse lattice temperatures well above this critical
temperature.
Computing the ground state spin-lattice configuration is typically
a non-trivial task. Like the large number problem of pixel con-
figurations in statistical image restoration, the number of possible
configurations for the spin-lattice is rather daunting to consider. To
efficiently sample the configuration space and find an approximate
ground state of the spin-lattice, we use the so-called Metropolis
Monte Carlo algorithm [Metropolis et al. ]. The algorithm is as
follows: (1) Choose a spin on the lattice at random. (2) Flip the
spin. Spin up goes to spin down. Spin down goes to spin up. (3)
Compute the energy difference between the previous configuration
of the spin-lattice and the new configuration, that is compute
∆E = E
− E, (2)
where E
is the energy of the new lattice configuration and E is
the energy of the previous lattice configuration. (4) If ∆E ≤ 0 ,
then keep the new, lower energy spin-lattice configuration. (5) If
∆E ≥ 0 , then draw a random number R between 0 and 1. (6)
Accept the new spin-lattice configuration if and only if
R ≤ e
. (3)
(7) Otherwise, keep the old spin-lattice configuration and repeat the
process for the next randomly chosen spin. The key idea behind the
Metropolis algorithm is that as we randomly walk through the spin-
lattice configuration space, we systematically reject the majority of
steps that increase the energy of the lattice configuration, allowing
a relatively quick convergence to the ground state solution. In Ap-
pendix B, the FORTRAN source code of the programs written to
find the approximate ground state configurations of the two- and
three-dimensional Ising models via the Metroplois algorithm are given.
In the context of binary image restoration, we propose to use the
two-dimensional binary Ising model as follows. Consider only unit
interactions on the lattice, such that the sets of coupling constants
are {μij = 1} and {Jijkl = 1}, and let the degraded binary image
be the initial configuration of the spin-lattice {Sij }. We then set the
externally applied magnetic field term, {Hij }, to be some approxi-
mation of the original image obtained by other means. By using the
approximated original image as the external bias field, it follows
that it is energtically favorable for the spins of the degraded image
to become aligned with this approximated original image. Via spin-
spin interactions, the information in the approximated bias field can
then also be distributed in a correlated way among the spins on the
lattice. It is our hope that these interactions will compensate for the
undoubtably imperfect approximation of the original image. The
final restored image is the approximated ground state spin-lattice
configuration found using the Metropolis algorithm.
For grayscale images, the restoration process proposed is similar.
However, instead of using the two-dimensional Ising model, we
employ the three-dimensional binary Ising model to couple together
the eight two-dimensional bit-planes that represent the pixels of the
grayscale image.
3 Numerical Results
For the numerical results on binary and grayscale image restoration
using the two- and three-dimensional binary Ising model presented
here, the emphasis was to study the general mechanics of the im- age restoration process and the resulting qualitative features of the
restored images. As such, we have not focused on how to construct
an efficient and accurate approximation of the original image from
the degraded ones to be used as the external bias field. Instead,
we consider only the two extremum cases when the external bias
field is taken to be the exact, original binary or grayscale image
and when the external bias field is taken to be the degraded image
itself. The idea for using the degraded image as the external bias
field assumes that a large fraction of the pixels are uncorrupted and
thus retain some information about the original image the spin-spin
interactions may use in the restoration process.
Figure 4: Binary image restoration of Lena via the two-
dimensional Ising model. (Upper Left) Original binary image of
Lena. (Upper Right) Degraded binary image of Lena ( σ
= 1 ).
(Lower Left) Restored image of Lena using the original binary im-
age of Lena as the external bias field. (Lower Right) Restored image
of Lena using the degraded image of Lena as the external bias field.
restoration above. In Figure 7 and 8, the qualitative features of the
grayscale image restoration process for the three-dimensional and
quasi-two-dimensional Ising models are depicted in several sample
images.
4 Conclusion
Despite the limited success of the preliminary results presented
here, we argue that the generalized framework of the binary Ising
model as it relates to the image restoration process is both quite
unique and merits further study. All in all, We have really only con-
sidered a relatively basic, straightforward approch to using the Ising
model. It is likely that this process can be significantly improved by
considering not only simple techniques such as preconditioning the
degraded image with smoothing filters, but also through more ad-
vanced, complex methods that exploit non-uniform spin-field and
spin-spin coupling schemes. In addition, it is quite possible that
many of the issues observed in the simple approches we have con-
sidered are fixed by using higher-order nearest-neighbor interac-
tions. Whatever the case may be, these advanced coupling schemes
and higher-order nearest-neighbor interactions would undoubtably
carry over to higher dimensional binary Ising models that may be
useful for color image restoration. Of course, however, all such
speculations require further numerical and theoretical study.
Acknowledgements
Thanks Dr. Morris! It was great semester. I hope you have a good
holiday.
References
CARLUCCI, D. M., AND INOUE, J.-I. 1999. Image restoration
using the chiral Potts spin glass. Phys. Rev. E 60 , 3, 2547–2553.
CHANDLER, D. 1987. Introduction to Modern Statistical Mechan-
ics. Oxford University Press, Inc.
HUANG, K. 1987. Statistical Mechanics , Second ed. John Wiley
and Sons, Inc.
INOUE, J.-I., AND CARLUCCI, D. M. 2001. Image restoration
using the Q-Ising spin glass. Phys. Rev. E 64 , 036121.
INOUE, J.-I. 2001. Application of the quantum spin glass theory
to image restoration. Phys. Rev. E 63 , 046114.
ISING, E. 1925. Beitrag zur Theorie des Ferro-und
Paramgnetismus. Z. Phys. 31 , 253.
METROPOLIS, N., ROSENBLUTH, A. W., TELLER, A. H., AND
TELLER, E. Equation of State Calculations by Fast Computing
Machines. J. Chem. Phys..
PATHRIA, R. K. 1996. Statistical Mechanics , Second ed. Elsevier
Butterworth-Heinemann.
TANAKA, K., INOUE, J.-I., AND TITTERINGTON, D. M. 2003.
Probabilistic image processing by means for the Bethe approxi-
mation for the Q-Ising model. J. Phys. A 36 , 11023–11035.
TANAKA, K. 2002. Statistical-mechanical approach to image pro-
cessing. J. Phys. A 35 , R81–R150.
Appendix A: MATLAB M-Files
2 % Math 336 - Image Processing - Final Project 3 % 4 % This MATLAB script is used for generating the noisy binary image data in 5 % a format suitable to be read-in by the FORTRAN program ising2.x. 6 % 7 % Marty Kandes 8 % Computational Science Research Center / Department of Physics 9 % San Diego State University 10 % Fall 2008 11 % ------------------------------------------------------------------------- 12 clear all; close all; clc; % Clear MATLAB workspace. 13 f = imread(’lena.jpg’); % Read image from graphics file. 14 f = imresize(f,[256,256]); % Resize image. 15 f = im2double(f); % Convert image to double. 16 f = mat2gray(f); % Renormalize image’s grayscale. 17 mean = 0; % Set noise mean. 18 variance = 0.001; % Set noise variance. 19 n = imnoise(f,’gaussian’,mean,variance); % Add noise to image. 20 b = im2bw(n,graythresh(n)); % Convert image to binary. 21 imwrite(b,’lenagn0001.png’,’png’); % Write image to graphics file. 22 [M N] = size(b); % Get dimensions of binary image. 23 fid = fopen(’lenagn0001.dat’,’w’); % Open file to write out data. 24 for J = 1:N % 25 for I = 1:M % 26 fprintf(fid,’%1i \n’,b(I,J)); % Write binary image data to file. 27 end; % 28 end; % 29 status = fclose(fid); % Close file. 30 % ========================================================================= 31 % Math 336 - Image Processing - Final Project 32 % 33 % This MATLAB script is used for reading in the binary image data from the 34 % output of the FORTRAN program ising2.x to construct the restored binary 35 % image. 36 % 37 % Marty Kandes 38 % Computational Science Research Center / Department of Physics 39 % San Diego State University 40 % Fall 2008 41 % ------------------------------------------------------------------------- 42 clear all; close all; clc; % Clear MATLAB workspace. 43 M = 256; N = 256; % Set image dimensions. 44 load lenarestored.dat; % Load binary image data. 45 K = 0; % Initialize loop counter. 46 for J = 1:N % 47 for I = 1:M % 48 K = K + 1; % 49 b(I,J) = lenarestored(K,1); % Read binary image data into array b. 50 end; % 51 end; % 52 imwrite(b,’lenarestored.png’,’png’); % Write image to graphics file. 53 % ========================================================================= 54 % Math 336 - Image Processing - Final Project 55 % 56 % This MATLAB script is used for generating binary bit plane data of a 57 % noisy grayscale image in a format suitable to be read-in by the FORTRAN 58 % program ising3.x. 59 % 60 % Marty Kandes 61 % Computational Science Research Center / Department of Physics
62 % San Diego State University 63 % Fall 2008 64 % ------------------------------------------------------------------------- 65 clear all; close all; clc; % Clear MATLAB workspace. 66 f = imread(’lena.jpg’); % Read image from graphics file. 67 f = imresize(f,[256,256]); % Resize image. 68 mean = 0; % Set noise mean. 69 variance = 0.001; % Set noise variance. 70 n = imnoise(f,’gaussian’,mean,variance); % Add noise to image. 71 imwrite(n,’lenagn0001.png’,’png’); % Write image to graphics file. 72 n = double(n); % Convert image to double. 73 [M,N] = size(n); P = 8; % Set num bit planes and dims. 74 b = zeros(M,N,P); % Preallocate bit plane array. 75 b(:,:,1) = logical(mod(n,2)); % Compute bit planes. Level 1. LSB. 76 b(:,:,2) = logical(mod(floor(n/2),2)); % Level 2. 77 b(:,:,3) = logical(mod(floor(n/4),2)); % Level 3. 78 b(:,:,4) = logical(mod(floor(n/8),2)); % Level 4. 79 b(:,:,5) = logical(mod(floor(n/16),2)); % Level 5. 80 b(:,:,6) = logical(mod(floor(n/32),2)); % Level 6. 81 b(:,:,7) = logical(mod(floor(n/64),2)); % Level 7. 82 b(:,:,8) = logical(mod(floor(n/128),2)); % Level 8. MSB. 83 fid = fopen(’lenagn0001.dat’,’w’); % Open file to write out data. 84 for K = 1:P % 85 for J = 1:N % 86 for I = 1:M % 87 fprintf(fid,’%1i \n’,b(I,J,K)); % Write bit plane data to file. 88 end; % LSBP to MSBP. 89 end; % 90 end; % 91 status = fclose(fid); % Close file. 92 % ========================================================================= 93 % Math 336 - Image Processing - Final Project 94 % 95 % This MATLAB script is used for reading in the binary bit plane data of a 96 % output by the FORTRAN program ising3.x to construct the restored image. 97 % 98 % Marty Kandes 99 % Computational Science Research Center / Department of Physics 100 % San Diego State University 101 % Fall 2008 102 % ------------------------------------------------------------------------- 103 clear all; close all; clc; % Clear MATLAB workspace. 104 M = 256; N = 256; P = 8; % Set num bit planes and dims. 105 b = zeros(M,N,P); % Preallocate bit plane array. 106 load lenarestored.dat; % Load bit planes. 107 L = 0; % Initialize loop counter. 108 for K = 1:P % 109 for J = 1:N % 110 for I = 1:M % 111 L = L + 1; % 112 b(I,J,K) = lenarestored(L,1); % Read bit plane data into array. 113 end; % 114 end; % 115 end; % Compute restored image from bit planes. 116 f = uint8(2(2(2(2(2(2(2*b(:,:,8)+b(:,:,7))+b(:,:,6))+b(:,:,5))+b(:,:,4))+b(:,:,3))+b(:,:,2))+b(:,:,1)); 117 imwrite(f,’lenarestored.png’,’png’); % Write image to graphics file. 118 % =========================================================================
Appendix B: FORTRAN Source Code
2! Math 336 - Image Processing - Final Project 3! 4! Binary Image Restoration using the 2D Ising Model 5! 6! Marty Kandes 7! Computational Science Research Center / Department of Physics 8! San Diego State University 9! Fall 2008 10! ------------------------------------------------------------------------- 11 PROGRAM ISING 12 IMPLICIT NONE 13 14 INTEGER, PARAMETER :: NITS = 6553600! Num Monte Carlo iterations. 15 INTEGER, PARAMETER :: NINV = 1000! Num inverse temps. 16 INTEGER, PARAMETER :: NPIX = 256! Num pixels in X. 17 INTEGER, PARAMETER :: NPIY = 256! Num pixels in Y. 18 19 INTEGER :: FILENUM! Input / output file number(s). 20 INTEGER :: I, J! Loop counters. 21 INTEGER :: U, V! Integer spin coordinates. 22 INTEGER :: DELTAE! Energy diff in spin configs. 23 24 INTEGER, ALLOCATABLE :: B(:,:)! Original binary image. 25 INTEGER, ALLOCATABLE :: H(:,:)! External magnetic field. 26 INTEGER, ALLOCATABLE :: S(:,:)! Spin lattice / restore image. 27 28 REAL, PARAMETER :: DELTAB = 0.01E0! Diff between inverse temps. 29 30 REAL :: X, Y! Real spin coordinates. 31 REAL :: BETA! Inverse temperature. 32 REAL :: ETA! Random number between 0 & 1. 33 34 FILENUM = 998! Initialize file number(s). 35 36 ALLOCATE(B(NPIX,NPIY))! Allocate arrays. Orig image. 37 ALLOCATE(H(NPIX,NPIY))! External field. 38 39 DO J = 1, NPIY! Read in external field. 40 DO I = 1, NPIX! 41 READ(FILENUM,*) H(I,J)! 42 IF (H(I,J) == 0) THEN! Convert 0 bits to -1. 43 H(I,J) = -1! Need -1 bits for calculations. 44 ENDIF! 45 ENDDO! 46 ENDDO! 47 FILENUM = FILENUM + 1! Increment file number. 48
49 DO J = 1, NPIY! Read in original, noisy 50 DO I = 1, NPIX! binary image to be restored. 51 READ(FILENUM,) B(I,J)! Convert 0 bits to -1. 52 IF (B(I,J) == 0) THEN! 53 B(I,J) = -1! 54 ENDIF! 55 ENDDO! 56 ENDDO! 57 FILENUM = FILENUM + 1! Increment file number. 58 59 !H = 0! Uncomment for no ext field. 60 61 DO J = 1, NINV! Loop over inv temps. 62 BETA = FLOAT(J)DELTAB! Compute current inv temp. 63 CALL RANDOM_SEED()! Seed random number generator. 64 S = B! Init spin lattice to orig im. 65 DO I = 1, NITS! Loop over num MC iterations. 66 CALL RANDOM_NUMBER(X)! Random X spin coordinate. 67 CALL RANDOM_NUMBER(Y)! Random Y spin coordinate. 68 CALL RANDOM_NUMBER(ETA)! Random number between 0 & 1. 69 U = CEILING(FLOAT(NPIX)X)! Integer X spin coordinate. 70 V = CEILING(FLOAT(NPIY)Y)! Integer Y spin coordinate. 71 DELTAE = H(U,V)! Compute difference in the 72 IF (U.NE.1) THEN! configuration energy of the 73 DELTAE = DELTAE + S(U-1,V)! spin lattice if we were to 74 ENDIF! flip the current spin under 75 IF (U.NE.NPIX) THEN! consideration. Here, we use 76 DELTAE = DELTAE + S(U+1,V)! non-periodic boundary 77 ENDIF! conditions. 78 IF (V.NE.1) THEN! 79 DELTAE = DELTAE + S(U,V-1)! Comment out these if 80 ENDIF! statements to consider Ising 81 IF (V.NE.NPIY) THEN! model without local 82 DELTAE = DELTAE + S(U,V+1)! interactions. 83 ENDIF! 84 DELTAE = 2S(U,V)DELTAE! Final energy difference. 85 IF (DELTAE.LE.0) THEN! Use Metropolis algorithm 86 S(U,V) = -S(U,V)! to decide if we flip the 87 ELSEIF ((-BETAFLOAT(DELTAE)).LT.LOG(ETA)) THEN! current spin 88 S(U,V) = S(U,V)! under consideration or keep 89 ELSE! it’s present state. 90 S(U,V) = -S(U,V)! 91 ENDIF! 92 ENDDO! 93 DO V = 1, NPIY! 94 DO U = 1, NPIX! 95 IF (S(U,V) == -1) THEN! Convert -1 bits to 0 bits. 96 S(U,V) = 0! Need 0 bits for image file. 97 ENDIF! 98 WRITE(FILENUM,) S(U,V)! Write restored image to file. 99 ENDDO! 100 ENDDO! 101 FILENUM = FILENUM + 1! Increment file number. 102 ENDDO! 103 104 DEALLOCATE(B,H,S)! Deallocate arrays. 105 106 STOP 107 END 108! ========================================================================= 109! Math 336 - Image Processing - Final Project 110! 111! Grayscale Image Restoration using the 3D Ising Model 112! 113! Marty Kandes 114! Computational Science Research Center / Department of Physics 115! San Diego State University 116! Fall 2008 117! ------------------------------------------------------------------------- 118 PROGRAM ISING 119 IMPLICIT NONE 120 121 INTEGER, PARAMETER :: NITS = 52428800! Num Monte Carlo iterations. 122 INTEGER, PARAMETER :: NINV = 1000! Num inverse temps. 123 INTEGER, PARAMETER :: NPIX = 256! Num pixels in X. 124 INTEGER, PARAMETER :: NPIY = 256! Num pixels in Y. 125 INTEGER, PARAMETER :: NBPZ = 8! Num bit planes. 126 127 INTEGER :: FILENUM! Input / output file number(s). 128 INTEGER :: I, J, K! Loop counters. 129 INTEGER :: U, V, W! Integer spin coordinates. 130 INTEGER :: DELTAE! Energy diff in spin configs. 131 132 INTEGER, ALLOCATABLE :: B(:,:,:)! Original, noisy binary image. 133 INTEGER, ALLOCATABLE :: H(:,:,:)! External magnetic field. 134 INTEGER, ALLOCATABLE :: S(:,:,:)! Spin lattice / restore image. 135 136 REAL, PARAMETER :: DELTAB = 0.01E0! Diff between inverse temps. 137 138 REAL :: X, Y, Z! Real spin coordinates. 139 REAL :: BETA! Inverse temperature. 140 REAL :: ETA! Random number between 0 & 1. 141 142 FILENUM = 998! Initialize file number(s). 143 144 ALLOCATE(B(NPIX,NPIY,NBPZ))! Allocate arrays. Orig image. 145 ALLOCATE(H(NPIX,NPIY,NBPZ))! External field. 146 ALLOCATE(S(NPIX,NPIY,NBPZ))! Spin lattice / rest image. 147 148 DO K = 1, NBPZ! 149 DO J = 1, NPIY! 150 DO I = 1, NPIX! 151 READ(FILENUM,*) H(I,J,K)! Read in external field. 152 IF (H(I,J,K) == 0) THEN! Convert 0 bits to -1. 153 H(I,J,K) = -1! Need -1 bits for cals. 154 ENDIF! 155 ENDDO! 156 ENDDO! 157 ENDDO! 158 FILENUM = FILENUM + 1! Increment file number.
1
0.01 0.1 1 10
BWC
β
External Field + Interactions External Field Interactions
1
0.01 0.1 1 10
BWC
β
External Field + Interactions External Field Interactions
Figure 5: (Top) Grayscale image restoration of the degraded
grayscale image of Lena ( σ
= 1 ) versus the inverse lattice temper-
ature using the three-dimensional Ising model. In this case, original
grayscale image of Lena was used as the external bias field. (Bot-
tom) Grayscale image restoration of the degraded grayscale image
of Lena ( σ
= 1 ) versus inverse lattice temperature using the quasi-
two-dimensional Ising model. Again, the original grayscale image
of Lena was used here as the external bias field.
1
0.001 0.01 0.1 1
BWC
σ
Lena Degraded Lena Restored OB Lena Restored NB
1
0.001 0.01 0.1 1
BWC
σ
Lena Degraded Lena Restored OB Lena Restored NB
Figure 6: (Top) Grayscale image restoration of the degraded
grayscale images of Lena at an inverse temperature of β = 1 versus
the magnitude of the gaussian noise variance, σ
, using the three- dimensional Ising model. (Bottom) Grayscale image restoration of
the degraded grayscale images of Lena at an inverse temperature
of β = 1 versus the magnitude of the gaussian noise variance us-
ing the quasi-two-dimensional Ising model. In both cases, the solid
lines and open squares are the measured quality of the degraded
images of Lena with respect to the original image. The dotted lines
and open circles are the measured quality of the restored images
generated by using the original grayscale image as the external
bias field. The dashed-dotted lines and the open triangles are the
measured quality of the restored images generated by using the de-
graded images as the external bias field. Note that both the external
bias fiel and spin-spin interactions were used in the restoration pro-
cess.
Figure 7: Grayscale image restoration of Lena via the three-
dimensional Ising model. (Upper Left) Original grayscale image of
Lena. (Upper Right) Degraded grayscale image of Lena ( σ
= 1 ).
(Lower Left) Restored image of Lena using the original grayscale
image of Lena as the external bias field. (Lower Right) Restored
image of Lena using the degraded image of Lena as the external
bias field.
Figure 8: Grayscale image restoration of Lena via the quasi-two-
dimensional Ising model. (Upper Left) Original grayscale image of
Lena. (Upper Right) Degraded grayscale image of Lena ( σ = 1 ).
(Lower Left) Restored image of Lena using the original grayscale
image of Lena as the external bias field. (Lower Right) Restored
image of Lena using the degraded image of Lena as the external
bias field.