How can I threshold an image to get only one color?(red)

1 次查看(过去 30 天)
my image is an Oil red O stain of a tissue and I need to remove everything but the red part of the image however this code is making the blue part almost black. Additionally I want to be able to make a slider that lets me manually adjust the threshold, sort of like in imageJ. Thanks. Here's my code so far:
clc;
clear;
close all;
% read in tiff image and convert it to double format
I=imread('NEW_tissue.tif');
% perform thresholding by logical indexing
image_thresholded =I;
image_thresholded(I>155) = 160;
image_thresholded(I<140) = 0;
% display result
figure()
subplot(1,2,1)
imshow(I,[])
title('original image')
subplot(1,2,2)
imshow(image_thresholded,[])
title('thresholded image')

回答(1 个)

Image Analyst
Image Analyst 2018-6-26
Unfortunately you forgot to attach 'NEW_tissue.tif'. Anyway there already is such a function. Go to the Apps tab of the tool ribbon and run the Color Thresholder App. Load in your image, pick your color space, and start sliding away! You should be able to create a mask of all the red pixels. Or see my File Exchange where I did that in a demo.
If you have a grayscale image and want to manually and visually/interactively threshold it, see my thresholding app in my File Exchange: https://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862&sort=downloads_desc
  1 个评论
Serena Tenhumberg
Serena Tenhumberg 2018-6-26
So if I use the app is there a way to apply the same parameters that I adjusted with one picture to a folder of pictures?

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by