MATLAB Answers

Find the Euclidean distance of each pixel from a user-selected pixel in color space and displays scaled images from 0 to the current max distance.

47 views (last 30 days)
Hi,
Can someone help me? Sorry for bad english
I need to find the Euclidean distance of each pixel from a user-selected pixel in RGB space and other in Lab space. Then displays 2 scaled images either from 0 to the current max distance, or from 0 to the theoretically maximum possible distance in a given color space. The result should be like
I'm new to this
Here is my current code
I dont know if im on the right way
Thanks everyone

  4 Comments

Show 1 older comment
KALYAN ACHARJYA
KALYAN ACHARJYA on 23 Jan 2021
Arsen Comments moved here
Hi, thanks for the reply
I need to calculate the Euclidean distance between pixel colors, not between their coordinates
With function "ginput(1)" i need to select one pixel and then find distance of each pixel from the user-selected pixel
first in RGB color space and then in LAB color space
Then I need to display 2 images:
one will display the Euclidean distance of each pixel from the user-selected pixel in RGB space and the other in space Lab.
Red dot is our selected pixel.
I need to scale the images with distances appropriately.
And the result should be like this in 2 different color spaces
Im really sorry for long reply
Best regards, Arsen
KALYAN ACHARJYA
KALYAN ACHARJYA on 23 Jan 2021
"I need to calculate the Euclidean distance between pixel colors, not between their coordinates"
Distance measure between to positions/locations, the indices (row number and column number) of particular color level exactly represent the same.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 23 Jan 2021
Just do this
[x, y] = ginput(1);
row = round(y);
col = round(x);
rp = double(rgbImage(row, col, 1));
gp = double(rgbImage(row, col, 2));
bp = double(rgbImage(row, col, 3));
[r, g, b] = imsplit(double(rgbImage));
colorDistance = sqrt((r - rp).^2 + (g - gp).^2 + (b - bp).^2);
imshow(colorDistance, []);
See attached demo for Delta E demos. Delta E is the coor distance in LAB color space.

  4 Comments

Show 1 older comment
Image Analyst
Image Analyst on 23 Jan 2021
Assuming you have your lab image in a variable called labImage, just make the straightforward changes:
[x, y] = ginput(1);
row = round(y);
col = round(x);
lp = double(labImage(row, col, 1));
ap = double(labImage(row, col, 2));
bp = double(labImage(row, col, 3));
[lChannel, aChannel, bChannel] = imsplit(double(rgbImage));
colorDistance = sqrt((lChannel - lp).^2 + (aChannel - ap).^2 + (bChannel - bp).^2);
imshow(colorDistance, []);
You might look up the deltae() function in MATLAB.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!