How I can compare one pixel to a neighbor pixel and also another pixel?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
Also, how I can make a difference histogram of the comparison results? Or how I can make a difference histogram generally?
Accepted Answer
Image Analyst
on 14 Jan 2013
0 votes
How do you want to compare them? Do you want to subtract them? If so you can use conv2(). Do you want to know how many times one gray level occurs next to another gray level? If so you can use graycomatrix().
13 Comments
Teemu
on 14 Jan 2013
I want to compare gray levels by pixel to pixel and make difference histogram from the compare data.
Teemu
on 14 Jan 2013
what is the best way to do it?
Image Analyst
on 14 Jan 2013
Define "compare" - does that mean subtract? Define "difference histogram" - that is not standard terminology.
diffImage = conv2(grayImage, [-1 -1 -1;-1 8 -1; -1 -1 -1], 'valid');
[counts values] = hist(diffImage(:));
Teemu
on 15 Jan 2013
I said it all wrong. I mean that I have to calculate gray level difference between neighbour pixels and also pixel distance 1-3 in x- and y-directions. and then make histogram from the calculate data.
Image Analyst
on 15 Jan 2013
If you only want the above, below, and beside pixels then you need to change the kernel:
diffImage = conv2(grayImage, [0 -1 0;-1 4 -1; 0 -1 0], 'valid');
[counts values] = hist(diffImage(:));
I don't know what "pixel distance 1-3" is. Again, that is non-standard terminology.
Teemu
on 15 Jan 2013
I mean neighbour pixels and next to neighbour pixel, so there will be gray level compare for neighbour pixels and pixels which are two pixels away (next to neighbour pixels). Thanks for your answers.
Image Analyst
on 15 Jan 2013
You said "and also" so I thought it was a different thing. What the conv does is to take the (central pixel - top pixel) + (central pixel - left pixel) + (central pixel - right pixel) + (central pixel - bottom pixel) and then sums them up. So each output pixel is the sum of the pixel differences of the four closest neighbors. Is that what you want? If you want the mean instead of the sum, you can use [0 -1 0;-1 4 -1; 0 -1 0]/4 as the kernel - it's the same but divided by 4 to get the average delta gray level.
Teemu
on 15 Jan 2013
ok, now I understand. How I can do it when the pixel are not neighbour pixels?
Image Analyst
on 15 Jan 2013
Enlarge the mask (the sliding window). If you want, you can use a 5 by 5 window and only consider pixels that are 2 away. The value in the kernel window is the multiplicative factor on the intensity. So if you want to sum the pixel differences between the center and the 4 corners in a 5 by 5 you'd use this:
-1 0 0 0 -1
0 0 0 0 0
0 0 4 0 0
0 0 0 0 0
-1 0 0 0 -1
You can use any pattern and any weights that you want.
Teemu
on 15 Jan 2013
Ok, Thank you for answers.
Teemu
on 13 Feb 2013
How I can do it without conv2 function? Can I do it with loop? So I like to subtract pixel gray level to it´s neighbour pixel gray level using loop. How can I do it?
Image Analyst
on 13 Feb 2013
No comment.
Teemu
on 13 Feb 2013
ok. If you know the answer could you help me?
More Answers (0)
Categories
Find more on Texture Analysis in Help Center and File Exchange
Products
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)