From the ancient tradition, undoubtedly, came the assumption that whatever form Martians took it would be warlike and hostile to white, Anglo-Saxon incursions.
Clearly inspired by the deeds of fairy-tale knights and heroes of the American West, Burroughs's Captain Carter slays ugly humanoid giants and marries a beautiful red-skinned princess.
By 1899 the frontier had disappeared, having engendered a number of quasi-mystical American heroes with whom [Theodore] Roosevelt hoped to be associated, a line that began with Captain John Smith, included Daniel Boone and Davy Crockett, and ended with Buffalo Bill Cody.
Captain Smith, who came ashore on a strange land populated by a noble yet fierce people, may be considered the prototype of the American traveler through space, the figurative ancestor of Burroughs's Captain John Carter. "A typical Southerner of the highest type" from Virginia, Carter in 1866 began a series of adventures on Mars the high point of which is the rescue of a beautiful, red-skinned princess, a literary descendant of Pocahontas, who in a romantic interlude rescued Captain Smith from certain death at the hands of her father.
With the Western frontier closed, Americans were clearly looking for new territories in which to have, as Huck Finn put it, "howling adventures among the Injuns," and most recent commentators on A Princess of Mars have observed the imperial connection.
The green giants of Mars may be stand-ins for the Apaches of Arizona, with their fierce love of cruelty for its own sake, but it is I think a mistake to think of A Princess of Mars as a racist allegory. Yes, Burroughs borrows stereotypical characteristics of American Indians with which to endow his Barsoomians, but as Carter points out they are shared by the Tharks and Heliumites, who at the start of the romance are inveterate enemies.
An atavistic survivor of King Arthur's court, Burroughs's hero is clearly abstracted from the heroes of Walter Scott and Fenimore Cooper (he is a veteran of Indian wars as well as the War Between the States).
The good Indian/bad Indian trope is common in Western novels and movies. Either way the Indians are savages compared to the white man. The good Indians need the white man's help to stop the bad Indians so they can enjoy harmonious relations.
For more on the subject, see Stereotypes in A Princess of Mars and Stereotypes in Tarzan of the Apes.