Namely, the European power that colonized much of the Middle East and India, the British Empire. How were they able to colonize several parts of the Middle East like Egypt (a former territory of the Ottoman Empire) and the whole of India when back then it was home to strong empires and nation-states like the Ottoman Empire, Persia, the Mughal Empire, and the Maratha Empire which might be more stronger than Japan and Korea in the 18th and 19th centuries?
I'm sure the Qing Dynasty would be hard to colonize but why has no European power tried to colonize Japan or Korea back then when the two countries might be easier to colonize?
There are a few reasons, I mainly know more about East Asia in the 19th Century than colonization Middle East and India:
East Asia is a long way from Europe, especially Japan which apart from a few Dutch traders had little contact with the West until the mid-1800s. It's logistically quite hard to administrate and supply troops or colonies that far away from Europe. Until the steam powered ship and the Suez canal, it would have been a long treacherous voyage around Africa. Until the 1800s Europeans still don't know very much about China, especially about the interior, and few European's speak Chinese.
East Asia definitely wouldn't have been a walk-over by any means. The Qing Empire was arguably one of the first modern Empires, and it's often argued that it wasn't until the early 1800s, with serious ecological disasters, that the Qing economically started to lag behind Europe.
In the mid to late 1800s starting from the first opium war in 1839 we do see some colonization of China. The British took and held Hong Kong from 1841 til 1997. A number of other ports were opened and leased to European powers, such as the German presence in Tsingtao. The trade agreements forced on China after the opium wars were seen as highly humiliating "unequal treaties" by the Chinese. Of course there are also a series of Japanese invasions and colonisation in the later 1800s.
Japan after 1868 and the Meiji Restoration went through a huge period of social change and industrialisation. Similar unequal treaties were imposed after Commodore Perry visited Japan with a lot of warships in 1853. The Americans initially wanted to use Japanese ports to refuel pacific whaling ships with coal. The Japanese we conciliatory towards the west allowing access and trade while employing lots of western specialists to help "modernise" (although that might a problematic term) the country.
Sources:
when India and the Middle East had empires more powerful than Japan and Korea like the Mughals and the Ottomans?
Your question is based on a faulty premise. India did not have a powerful empire to resist the British. It had the opposite: the ruined, shattered remains of a once-powerful empire, a patchwork of little kingdoms busy fighting each other, which the Brits took advantage of.
The Mughal-Maratha wars lasted over four decades and ruined both sides. Between 1680 when Aurangzeb invaded Bijapur, until his death in 1707, there was more or less continuous warfare between the two sides. It bankrupted their treasury, decimated their army, fomented tremendous unease and disunity within. In fact after Aurangzeb died the Mughals were so weakened that in a few short years the Marathas had completely annihilated them. The Mughal “emperor” was just a Maratha puppet who controlled nothing outside a few square kilometers around Delhi.
And the Marathas were no better off, the wars had drained them to the point where they couldn’t control what they’d won either. Chunks of former Mughal territory began splitting up, there were literally hundreds of little princes, all frantically trying to stake out their own little kingdoms, busy fighting their neighbors for control.
The British “conquest” is a direct result of that, starting in Bengal. During Mughal times, Bengal was ruled by a Nawab who was the vassal and direct appointee of the Mughal court. Alivardi Khan was Nawab of Bengal at the time, but he died and now there was no Mughal Empire anymore to direct succession. A battle broke out – his grand-nephew Siraj-ud-Daulah became Nawab, but he was young and had no power base and his own army chief opposed him. The army chief, a man named Mir Jafar, hatched a plan to use the British to betray Siraj and kill him, and become Nawab himself.
So British “rule” actually started when Mir Jafar connived with British traders in Bengal to use their mercenaries under Robert Clive to betray Siraj-ud-Daulah, so he could become Nawab instead. But he made a mistake trusting the British, because they had no intention of letting him rule, and eventually took over in his place. That’s how the Brits gained their first foothold in India. And from there on, it was a matter of going after all those little kingdoms fighting each other. Support one against another, share the spoils, then come back and challenge the one that just sided with you.
All of this was possible precisely because your premise is wrong. There was no powerful empire in India at the time. The Brits arrived just in time to witness the breakup of the Mughal Empire and to pick up the pieces.
It's also worth noting that not all the Middle East was colonized. Turkey wasn't, for instance (Mustafa Kemal Atatürk led the nationalist resistance against such an attempt). Likewise, Saudi Arabia was never colonized (unless you count Ottoman control of the Hejaz). Iraq was colonized, but really were mostly in charge of their own affairs rather quickly, officially the Mandate for Iraq only lasted fom 1921-1932. Likewise, Jordan, Syria, and Lebanon were only mandates for slightly longer (1921-1946). Iran was never colonized, colonized, but Russia and the UK did carve out separate spheres of influence in the country for a time (a good way to learn some of this history is to read the history of William Morgan Shuster, they're going to make a Hollywood movie about him some day). Oman likewise experienced a period of British influence, but was never colonized. North Yemen was never colonized by Europeans, though South Yemen was ruled by the British for more than a century.
The point is that much of the Middle East was never colonized like North America, South America, Africa, the Pacific, North Africa, South Asia, Southeast Asia, etc. were. In large part that's probably because it was under the control of two great empires: the Ottoman Empire and Qajar Iran (the rest under the control of either very local leaders, leading to things like the Trucial States). The "Concert of Europe" was generally worried what would happen if the Ottomans collapsed (this was known as the Eastern Question) so generally European powers like France and England did what they could to prevent Ottoman lands from being directly taken over because that would benefit Russia. As in China, though, they organized many beneficial trade concessions. Qajar Iran was similar, somewhat, but with Russia and Britain fighting over some of its hinterlands in the Great Game.
But generally, there was less colonialism by Europeans in the Middle East than you'd expect.
Well all those countries were colonized to some extent except Japan. Japan did have some unequal treaties forced on if but once that happened the country rapidly industrialized into a powerful country. Siam/Thailand was the only other Asian country to escape colonization and that was mostly since France and the UK wanted a buffer state (with Siam losing a bit of territory).
As for those empires. Well when they lost that territory they were in a state of decline.
British colonialism in india started quite early (the east india company was founded in 1600/1601) and there was not just one big indian empire. The topic itself is really complex but if you are interested I can link you some good sources. Colonialism in India and the partion of india were my main fields of study 2 years ago.