There were numerous reasons as to why so large, well-established empires like the Russian and the Ottoman Empires were not able to quickly adapt and modernize in the way that much smaller nations did.
For starters, these two empires had very large territories. The vast territories meant that the laws and the modernization can not be implemented very well in all parts of the empire. Also, big problem was that in the borders of these empires lived people from lot of different ethnic and religious groups, which was largely making them empires where the people were not united, had different points of view, and different goals.
Japan on the other hand, is much smaller. The population of this nation had the same ethnic, religious, and cultural background, thus the nation was united in all aspects. That led to easy transformation and modernization of the society without any particular problems.