How count crack pixel for image process and compare it with original

조회 수: 2 (최근 30일)
yasmin ismail
yasmin ismail 2023년 7월 11일
편집: DGM 2023년 7월 11일
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
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
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
yasmin ismail
yasmin ismail 2023년 7월 11일
@Parth Saraf does the crack pixel in original image count whole pixels of the image width*length?
and crack pixel of the processed image only the white area of the image which is indication of crack or also the total number of pixels width*length? I want this ratio to measure the true positive fraction to evaluate my model which is used for crack detection , so what I said is correct or not?
DGM
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(:))
sumorig = 8355840
% the scale of this image is [0 1]; the other is [0 255]
summask = sum(mask(:))
summask = 32768
% 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
garbagenumber = 0.0039
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!

Translated by