# How to change the color of each pixel in a masked image?

조회 수: 24(최근 30일)
JovanS 2022년 10월 7일
댓글: JovanS 2022년 10월 12일
I found the Euclidean distances between each pixel of the mask and six reference colors. Now i want to change the color of every pixel which is in the skin lesion (masked image). Each pixel has to change color and will take the color of the shortest euclidean distance ( for example if the shortest euclidean distance is the one with red color , the pixel will turn into red). So I have to create a new image in which every pixel of mask will obtain one color of the 6 reference colors. Then the last step is to check if the number of pixels belonging to each reference colour exceeds by 5% of the total number of pixels of the lesion. If this occurs the color score is incremented by 1, otherwise the color score of each color is 0.
Any idea for doing this procedure ?
I attach my matlab code so far .
##### 댓글 수: 1표시 없음숨기기 없음
JovanS 2022년 10월 11일

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

### 채택된 답변

Image Analyst 2022년 10월 11일
You just didn't use the min function like I suggested in your other post. Here's the relevant snippet. The full demo is attached.
% Stack all the delta E into a 3-D image.
stack_array = cat(3,deImage_bg,deImage_wh,deImage_bl,deImage_red,deImage_db,deImage_lbr);
% Produce a classified image where the value is the slice that has the lowest delta E.
[~, classifiedImage] = min(stack_array, [], 3);
hFigClassified = figure;
imshow(classifiedImage, [])
impixelinfo;
cmap = lines(6);
colormap(cmap);
hcb = colorbar(gca,'Ticks', 1:6, 'TickLabels', {'BlueGray', 'White', 'Black', 'Red', 'Dark Brown', 'LightBrown'});
hcb.Label.String = 'Color Category';
hold on;
visboundaries(lesionBoundary);
hold off;
title('Classified Image', 'FontSize',fontSize)
drawnow;
hFigClassified.WindowState = "maximized";
Here is the image showing the classifications. As you can see, most of the melanoma is classified as being in the dark brown category.
##### 댓글 수: 7표시 이전 댓글 수: 6숨기기 이전 댓글 수: 6
JovanS 2022년 10월 12일
편집: JovanS 2022년 10월 12일
ok thank you but one last question , column 1corresponds to bluegray , 2 to white , 3 to black , 4 to red , 5 to darkbrown and 6 to lightbrown?? because according to this , the most number of pixels are lightbrown. As we saw in classifiedimage the melanoma is classified as being in the dark brown category. @Image Analyst

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

### 추가 답변(1개)

Benjamin Thompson 2022년 10월 11일
See if this helps. There is probably a faster way to do it with color mapping functions in the Image Processing Toolbox but it does not take very long on your image size.
##### 댓글 수: 4표시 이전 댓글 수: 3숨기기 이전 댓글 수: 3
JovanS 2022년 10월 12일
I attach you the final code, if you could check it, thank you very much for your help!@Image Analyst

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

### 범주

Find more on Region and Image Properties in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by