How can I determine the percentage of rex pixels in an image?

1 view (last 30 days)
I need to find the number and percentage of all red pixels inside the black outlined template bodies in this dermatome map. I tried to develop a function to do this but am getting stuck (my attempt is below). Any tips, either on how to improve my code or another way of solving this issue would be much appreciated, My issue is I can find the number of red pixels on the page, but not specifically within the outlined bodies. Is there a way to code this so that it excludes everything outside of the black outline?
function [perc] = findRed(fname) %function header. reads: %"function [outputs] = function name(inputs) image_1 = double(imread(fname, tif)); %opens image that is a jpeg file,
%and converts to type double R = image_1(:,:,1); %initializes color layers, saves them as separate %arrays G = image_1(:,:,2);
B = image_1(:,:,3);
red = r == 255 & g == 0 & b == 0; %creates array of pure red pixel positions
[r c] = size(red); %finds the size of this red array
Red_pixels = (r*c); %gives the total number of pixels
black = r == 0 & g == 0 & b == 0; %creates mask of black pixels that are the outline
[row col] = size(black);
Outline = (row*col); %finds the number of black pixels
Total = Outline + %code that finds the area inside the outline...which i don't know how to do right now
perc = (Red_pixels/Total)*100 %hopefully this works?
end

Accepted Answer

Image Analyst
Image Analyst on 5 Jun 2014
You need to use color segmentation. See my File Exchange. I have one demo there that finds red pixels. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 Your method will only work for pure red things like computer graphics, not for real world red objects.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!