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

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.

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.

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

Start Hunting!
## 4 Comments

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/724857-find-the-euclidean-distance-of-each-pixel-from-a-user-selected-pixel-in-color-space-and-displays-sca#comment_1280807

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/724857-find-the-euclidean-distance-of-each-pixel-from-a-user-selected-pixel-in-color-space-and-displays-sca#comment_1280807

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/724857-find-the-euclidean-distance-of-each-pixel-from-a-user-selected-pixel-in-color-space-and-displays-sca#comment_1280817

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/724857-find-the-euclidean-distance-of-each-pixel-from-a-user-selected-pixel-in-color-space-and-displays-sca#comment_1280817

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/724857-find-the-euclidean-distance-of-each-pixel-from-a-user-selected-pixel-in-color-space-and-displays-sca#comment_1280822

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/724857-find-the-euclidean-distance-of-each-pixel-from-a-user-selected-pixel-in-color-space-and-displays-sca#comment_1280822

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/724857-find-the-euclidean-distance-of-each-pixel-from-a-user-selected-pixel-in-color-space-and-displays-sca#comment_1280847

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/724857-find-the-euclidean-distance-of-each-pixel-from-a-user-selected-pixel-in-color-space-and-displays-sca#comment_1280847

Sign in to comment.