A lot of people have already made good points.
I think a lot of it comes down to the uniform on a couple of levels.
With the NBA uniform, things like cornrows, afros, tattoos, scraggly facial hair and such are perfectly and clearly visible, and these things are definitely associated by a lot of people with “thugs.” The NFL uniform covers up the hair and also the vast majority of tattoos. And during the game, except for close-ups on the sidelines, you’re not going to get a good or lasting glimpse of the tattoos or facial hair.
It’s this:

Compared to this:

But now if that football player, was playing basketball, you’d see something more like this every second of the game:

Same Randy Moss, but I bet if he were playing basketball instead, he'd be viewed as more of thug, or by more people as a thug. If DeShawn Stevenson were playing football, a lot of people would never see those tats or beard and his "thug" image.
Also, the way players dressed on the sidelines, pre-dress code didn’t help either (which I’m sure is still engrained in a lot of people’s heads). While not all the players dressed like this, you’d see guys on the sideline that weren’t playing dressed like this, or coming to games, or doing post game interviews dressed like this:

But you don’t really see guys in the NFL in street clothes on the sideline or showing up to the arenas or doing post game interviews like this (at least I don’t think so, I don’t really watch football so I don't really know). Even though the NBA now has the dresscode, the pre-dress code image is still stuck in a lot of people’s minds.
And then it’s the dress by non-professionals too. You can drive by any park (city or suburbs) and see something like this:

And it’s even worse if they’re running shirts and skins. You don’t see anywhere near as many unorganized football games going on. So this aides the perception as well. Also, you can get so close to these games (organized or pick up) just walking down the street or in the park and hear the players swearing. You don't get anywhere near as close to pick up football games (or professional) to really hear what's going on or see the perceived "thug like" images of jewelry, tattoos, style of clothing, and language.
So then take these problems I mentioned and figure 30 NBA teams * 82 games * 7 game playoff series * 4 rounds + 30 or so major D1 programs * 35 or so game college seasons + a 1000 to 1 pickup basketball to football game ratio = a whole lot more basketball being seen than football, so this just exaggerates the perceived problem exponentially.
I think a large part of it is a collection of these things, plus also what other people mentioned too.