A thresholded Gaussian random field model is developed for the microstructure of porous materials. Defining the random field as a solution to stochastic partial differential equation allows for flexible modelling of nonstationarities in the material and facilitates computationally efficient methods for simulation and model fitting. A Markov Chain Monte Carlo algorithm is developed and used to fit the model to three-dimensional confocal laser scanning microscopy images. The methods are applied to study a porous ethylcellulose/hydroxypropylcellulose polymer blend that is used as a coating to control drug release from pharmaceutical tablets. The aim is to investigate how mass transport through the material depends on the microstructure. We derive a number of goodness-of-fit measures based on numerically calculated diffusion through the material. These are used in combination with measures that characterize the geometry of the pore structure to assess model fit. The model is found to fit stationary parts of the material well.