Comparison between the values ​​of pixels in the image matrix

This code to divide the image to Blocks After the divided we take the avrege of each block with size 4*4 pixel and store values in new matrix image called (a) Then we want to compare the value of each pixel in matrix (a) with all the other values of pixels in the same matrix when we find value equal another values in the same matrix put in other postion of those value zero. after that we store in the new image in first row we store the value of each pixel and in another row we store the number of pixel equals and its postion
if true
Range_Image=rgb2gray(imread('data.jpg'));
[m n]=size(Range_Image); Nbrx = floor(m./4);
Nbry = floor(n./4); Nd=1;
for i=1:Nbrx
for j=1:Nbry
Mat=Range_Image((i-1)*4+1:i*4,(j-1)*4+1:j*4);
sumpixel=sum(Mat(:));
avg=floor(sumpixel./16);
a(i,j)=avg;
%subplot(Nbrx,Nbry,Nd);
Nd=Nd+1;
end
end
figure(1),imshow(a,[])
count=0;
[x y]=size(a); Nbrx = floor(x);
Nbry = floor(y);
for i=1:Nbrx
for j=1:Nbry
a(i,j);
count=0;
if (a(i,j) ~= 0)
for z=1:Nbrx
for k=1:Nbry
if (a(i,j)==a(z,k))
count=count+1;
b(1,j)=a(i,j);
b(2,j)=count;
a(z,k)=0;
end
end
end
end
end
end
end

2 Comments

i want code for comparison of pixels in an image by considering a 3*3 matrix. for each pixel, a 3*3 matrix around the pixel should be considered and the pixel must be compared with both the diagonals of the considered 3*3 matrix, whether the pixel is greater than all the diagonal elements or not?
I think you meant to post this as your own new question rather than to send this to wissa as a comment to her. Please do so and we'll answer there.

Sign in to comment.

Answers (1)

I'm not sure I follow the grammar of this sentence: "Then we want to compare the value of each pixel in matrix (a) with all the other values of pixels in the same matrix when we find value equal another values in the same matrix put in other postion of those value zero. " I'm also not sure if you have a question or not - you didn't ask one. But I'd guess that it may be unlikely the average of one block will exactly equal the average of another block. Thus you will have to read an understand this FAQ: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F

4 Comments

For example: I have the following matrix
34 56 67 255
56 90 80 34
47 34 80 235
I want to compare the value of each pixel with all other values When I find a similar value, instead of the old value, set it to zero. The matrix becomes as follows
34 56 67 255
56 90 80 0
47 0 80 235
This is for the first pixel and when I find other similar value added to counter 1 count=count+1;
m % your matrix
compared = m == m(i,j);
compared(i,j) = false;
count = sum(compared(:));
m(compared) = 0;
Entisar, why do you want to do this thing? What will it accomplish for you?
I AM WORK TO DO WAY TO IMAGE COMPRESSION

Sign in to comment.

Categories

Tags

Asked:

on 11 Jun 2013

Commented:

on 10 Jan 2019

Community Treasure Hunt

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

Start Hunting!