Mean Square Error Code problem
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
% c. Calculate Mean Square Error (MSE)
mse_MRI = immse(MRI_original, enhanced_MRI); % Replace enhanced_MRI with your enhanced MRI image
mse_PET = immse(PET_original, enhanced_PET); % Replace enhanced_PET with your enhanced PET image
fprintf('Mean Square Error (MSE) for MRI: %f\n', mse_MRI);
fprintf('Mean Square Error (MSE) for PET: %f\n', mse_PET);
Error using immse (line 34)
A and B must have the same class.
Error in TASK_1 (line 27)
mse_MRI = immse(MRI_original, enhanced_MRI); % Replace enhanced_MRI with your enhanced MRI image
this error occur. how can i solve it?
1 Kommentar
MarKf
am 2 Feb. 2024
Bearbeitet: MarKf
am 2 Feb. 2024
The error tells you that MRI_original and enhanced_MRI do not have the same class ('uint8', 'int32', 'single','double' those), required by the function immse. Without the original data we can't say for certain, but likely in the enhancing process one changed class, so maybe -if they are the same size- just making them both double might work.
MRI_orig = double(MRI_original); %immse already does this btw if they are both integer class
enhd_MRI = double(enhanced_MRI);
mse_MRI = immse(MRI_orig, enhd_MRI); % which btw is just (norm(A(:)-B(:),2).^2)/numel(A);
Antworten (1)
Hassaan
am 2 Feb. 2024
% Convert images to double precision
MRI_original_double = im2double(MRI_original);
enhanced_MRI_double = im2double(enhanced_MRI);
PET_original_double = im2double(PET_original);
enhanced_PET_double = im2double(enhanced_PET);
% Compute Mean Square Error (MSE)
mse_MRI = immse(MRI_original_double, enhanced_MRI_double);
mse_PET = immse(PET_original_double, enhanced_PET_double);
% Print results
fprintf('Mean Square Error (MSE) for MRI: %f\n', mse_MRI);
fprintf('Mean Square Error (MSE) for PET: %f\n', mse_PET);
Converting to double precision (especially if the original images are in uint8 or uint16 format) might not always be necessary or the best choice depending on your specific situation. If both images are already in a compatible format (e.g., both are uint8 or both are uint16), you can directly compute the MSE without conversion. The key is ensuring both inputs to immse are of the same data type.
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Feel free to contact me.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Convert Image Type finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!