Foams are dispersions of gas bubbles within a liquid. They are often generated in porous and fractured media during co-injection of two fluids in the presence of a surfactant that lowers the surface tension to create and stabilize foam bubbles. Since foam viscosity is much larger than its constituent fluids, foam has many applications in subsurface engineering for controlling the mobility of fluids or carrying particulates. Pore geometry, thermodynamic conditions, molecular structure, and behavior of stabilizing agents such as surfactants or nanoparticles near gas/fluid or fluid/solid interfaces are some important factors affecting the stability and regeneration of foam in porous media. Those factors also explain why direct simulation of foam (re)generation is still a modeling challenge. We present the first direct pore-scale modeling simulation of foam generation and flow in two-dimensional (2D) and three-dimensional (3D) imaged rough fracture. We adapt the free surface lattice Boltzmann method for simulation in an imaged fracture geometry. The model couples liquid momentum transport between bubbles and diffusion of dissolved gas within liquid into bubbles and is adapted from the open solver LBfoam that originally does not account for porous media. To our knowledge, this is the first 3D model with foam flow driven by pressure gradient in a fractured porous medium, gas diffusion through liquid phase, and interface advection as a result of the aforementioned mechanisms at pore scale. We observe bubble coalescence, deformation, splitting, and trapping in the rough fracture, and we quantify them using morphological parameters (Minkowski functionals) at different surface tension, liquid viscosity, pressure gradient, and temperature conditions. Foam can be regenerated as gas migrates across a sharp fracture corner, caused by snap-off and lamella division mechanisms.