You're in luck. With a 4" waste pipe, you can use a flange that mounts on the inside of the pipe, so basically, just cut the pipe off flush with the floor. The flange needs to be anchored to not only the pipe, but to the floor. That looks like porcelain, which can be tough to drill holes in, but easy with the right tool. Some flanges aren't a nice 90-degree where they fit into the pipe, which means you need a little champher on the pipe. Some are a nice clean 90, so you don't have to worry about it.
Depending on whether it is a wood or slab would depend on what kind of anchors and the size of the holes you need to drill. Use SS screws so if they do get wet, they won't rust. If it is on a slab, then either plastic anchors or lead anchors.