How can I determine the percentage of rex pixels in an image?
Show older comments
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
More Answers (0)
Categories
Find more on Convert Image Type 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!