How count crack pixel for image process and compare it with original
2 次查看(过去 30 天)
显示 更早的评论
How can I find the ratio of no. of crack pixels in the processed image to the no. of crack pixels in ideal image as attached
1 个评论
DGM
2023-7-11
Don't save binarized images as JPG. Using JPG will damage the image and usually result in a larger file size for no benefit.
If your image is binarized (not the image in the JPG), use nnz() to count nonzero pixels. If you're reading the damaged image back from the JPG, you'll have to do a bunch of junk to try to salvage it before you can count anything.
回答(1 个)
Parth Saraf
2023-7-11
Hi,
You can try using this code:
processedImage = imread('processed_image.png');
crackPixelsProcessed = sum(processedImage(:));
originalImage = imread('original_image.png');
crackPixelsOriginal = sum(originalImage(:));
ratio = crackPixelsProcessed / crackPixelsOriginal;
Hope this helps!!
2 个评论
DGM
2023-7-11
编辑:DGM
2023-7-11
This code will obviously just give you a meaningless number.
% the original image
original = uint8(repmat(0:255,[256,1]));
imshow(original)
% a logical mask selecting the dark half
mask = original < 128;
imshow(~mask)
% you're adding up ALL values without concern for _which_ values are relevant
% you're also ignoring the fact that the ROI is defined by DARK regions
% also, data scale differs by a factor of 256 - regardless of area
sumorig = sum(original(:))
% the scale of this image is [0 1]; the other is [0 255]
summask = sum(mask(:))
% you're dividing a measure of area by a sum which is both irrelevant and mis-scaled
% the result is a meaningless number
garbagenumber = summask/sumorig
If you want a reference mask to compare against, you need to create that reference mask. You can't just use the original photo.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!