Mediaeval usage of the terms "duke", "count", "baron" and "lord" were fuzzier than many people like to believe, but generally have some broad connotations which Herbert seemed to be following.
Duke (derived from the Latin dux bellorum, war leader) was a major land-holder who, in many kingdoms, was also related in some way to the King/Emperor. In France, a duke's duchy sometimes contained counties, thus making him literally superior to the counts within his jurisdiction; in the English system, dukes were merely earls who were related to the Crown.
Counts (derived from the Latin comes, companion, implying courtier) were also major land-holders. On the continent, they were often the actual feudal lords over counties; in England, their equivalent, earls, were merely named after shires (the equivalent of counties), and often held the equivalent quantity of land to a county, but rarely actually governed a contiguous county.
Viscounts (also derived from comes) were, as the title implies, slightly less than counts, possibly holding subsidiary fiefs. In England, the title was not used until fairly late in the Middle Ages, but the Latin word viscomes was used to described sheriffs--royal appointees in those days charged with the actual governance of a shire--in Latin documents.
Baron is a really fuzzy term, whose derivation is actually largely unknown. In England for much of the Middle Ages, "baron" was more a descriptor than a title and applied to anyone who was a tenant in chief of the Crown, regardless of their actual rank. Thus, when we hear about the barons revolting against John, it doesn't mean just the lesser nobles, but all of John's direct vassals, including earls (there were no dukes as yet). Later on, as Parliament emerged as a part of English government, "baron" came to signify anyone who had a right to expect a summons to sit in the House of Lords for a session of parliament, even if they were not a tenant-in-chief.
Applying these titles to Dune:
The Atreides were explicitly glossed to be actual cousins--not just cousins in the sense of being fellow nobles--to the royal family, and hence, despite not being very wealthy, entitled to style themselves dukes. In theory, Leto had a (distant) claim to the throne, which was one of several reasons the Padishah Emperor feared him and worked to bring down his house. (In the end, Paul did not rely upon this claim, but on a combination of right-of-conquest and marriage to Irulan).
If the Fenrings have any ancestral, permanent fief, we never learn of it, but Hasimir is a companion to the Emperor, and for this alone, the styling of "Count" fits one of this historical uses of the title.
The Harkonnens may or may not have had any blood relationship to the throne, but were in a house in long-standing disgrace. Despite this, they were clearly land-holders of some note, with two permanent fiefdoms (Giedi Prime and, through marriage, Lankiveil) and the siridar-governorship of Arrakis. Vladimir Harkonnen held a seat in the Landsraad. Thus, the style of "baron" fits him in both its older English sense of "tenant-in-chief of the Crown" and its later-mediaeval sense of "entitled to sit in Parliament", even though his family's disgrace prevents them as being recognized with higher ranking titles such as "Count".