improved nx degree hist algorithm variation