How to compare the pixel of two image?

조회 수: 3 (최근 30일)
Tan Wen Kun
Tan Wen Kun 2015년 12월 10일
편집: Tan Wen Kun 2015년 12월 10일
How to turn the image into pure 0(white) and 1(black) ?
After turn into pure 0 and 1, how I sum the image so I can get total number pixel of 1?
count=0;
[x,y]=size(IM);
for i=1:x
for j=1:y
if IM(i,j)==1
if IM2(i,j)==1
count=count+1;
end
end
end
I want to compare both image and get how many % similarity.
similarity= count/totalobjectpixel
1.1 is total object pixel and 1.2 is result of segmentation i get.

채택된 답변

Stephen23
Stephen23 2015년 12월 10일
편집: Stephen23 2015년 12월 10일
Write vectorized code, it makes you life much easier:
thresh = 0.5; % threshold for converting to B&W
A_clr = rand(5,5,3); % random image
B_clr = rand(5,5,3); % random image
A_bw = A_clr>thresh; % convert to B&W
B_bw = B_clr>thresh; % convert to B&W
idx = A_bw==B_bw; % compare
idy = all(idx,3); % R==G==B
out = sum(idy(:)); % count
This code assumes that the image is a gray-scale RGB. Of course if you have the images toolbox you can use the more robust im2bw to convert to a black-and-white image:
  댓글 수: 1
Tan Wen Kun
Tan Wen Kun 2015년 12월 10일
편집: Tan Wen Kun 2015년 12월 10일
A_clr = imread('1.1.jpg'); %segment
B_clr = imread('1.2.jpg'); %original
How to superimpose the segment image to original image?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by