The precise quantification of myocardial infarction is crucial for evaluating therapeutic strategies. We developed a robust, color-based semi-automatic algorithm capable of infarct region detection, isolation and quantification with four different histological staining techniques, and of the isolation and quantification of diffuse fibrosis in the heart. Our method is developed based on the color difference in the infarct and non-infarct regions after histological staining. Mouse cardiac tissues stained with Masson's trichrome (MTS), hematoxylin and eosin (H&E), 2,3,5-Triphenyltetrazolium chloride and picrosirius red were included to demonstrate the performance of our method. We demonstrate that our algorithm can effectively identify and produce a clear visualization of infarct tissue in the four staining techniques. Notably, the infarct region on an H&E-stained tissue section can be clearly visualized after processing. The MATLAB-based program we developed holds promise for infarct quantification. Additionally, our program can isolate and quantify diffuse fibrotic elements from an MTS-stained cardiac section, which suggests the algorithm's potential for evaluating pathological cardiac fibrosis in diseased cardiac tissues. We demonstrate that this color-based algorithm is capable of accurately identifying, isolating and quantifying cardiac infarct regions with different staining techniques, as well as diffuse and patchy fibrosis in MTS-stained cardiac tissues.