Pretty soon not even your dreams may be private anymore. Japanese scientists have learned how to interpret what you're dreaming about by measuring your brain activity while you sleep. This data can then be plugged into an algorithm that reconstructs your dream so that it can be played back for you when you're awake, according to the journal Science.

In other words, scientists have invented a sort of dream-reading machine. Before long, you may never have to worry about forgetting what you dreamed about ever again. You'll be able to simply play your dreams back after you wake up in the morning.

The remarkable breakthrough makes use of a fairly straightforward idea: that when we visualize certain types of objects in our minds, our brains generate consistent neural patterns that can then be correlated with what is being visualized. For instance, when you imagine a chair, your brain fires in a pattern that occurs whenever a chair is visualized. An algorithm can then be used to tie the data from a brain scan to the appropriate correlated images. And voilà! Your dream can be reconstructed.

So far the research is still fairly rudimentary — researchers only claim to get the dream right about 60 percent of the time — but it's still an extraordinary turn for the science of the mind.

Here's how the study worked. Subjects were first asked to hook themselves up to an electroencephalography (EEG) machine, then to fall asleep within an fMRI machine. Scientists used the EEG readings to identify when the subjects began to enter a dreaming phase. The subjects were then promptly woken up and asked to recall what they were dreaming about. This process was repeated nearly 200 times for each subject.

Later, the scientists crunched this data and discovered that certain common types of objects from the subjects' dreams could be correlated with brain patterns as recorded by the fMRI scans. They then used an internet search engine to look for images that roughly matched the objects from the subjects' dreams, and entered all of this information into a learning algorithm that refined the model even further. That algorithm was then able to use the data from the dreamers' fMRI scans to assemble videos from the internet images, basically creating a primitive movie for each dream.

Again, the research is still in a rudimentary phase. So far these videos only represent crude approximations of the images from the subjects' dreams, but researchers claim that the machine’s predictions were still better than chance. Over time, the technology will improve as the algorithm learns.

The research could eventually revolutionize how dreams are interpreted and understood. Scientists may even glean valuable clues about what the mysterious function of dreaming is in the first place.

To learn more about how the science works, watch the video below: