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!