I'm not sure why we are able to diagnose and recommend remedies for other people’s ills so well, while we often have difficulty seeing our own.
You want the other person to know that you have judged him or her poorly all this time but now with your new insight you realize he or she are really not the terrible person you thought he or she was. This is not something you have to get off your chest. In fact you probably need to carry the weight of this with you for a while. Carrying that weight will help you change your thinking patterns toward this person and remind you not to judge so quickly.
You absolutely need to apologize for poor behavior. You may not need to apologize for poor thoughts.