Manipulation of RGB matrices possibly using NaN values?

조회 수: 3 (최근 30일)
Alex Weaver
Alex Weaver 2020년 2월 6일
답변: Subhadeep Koley 2020년 2월 6일
Using an RGB matrix, I am attempting to make a manipulation tool using grayscale. For instance, you can apply a gradient across the image as well as change the color of certain points at will. Even though the image below is black and white, the gradient will apply a full greyscale. I was wondering if it is possible to remove the black values and apply this gradient tool to just the white portion. For example, the left side would of the white area would stay white and would transition to black moving closer to the other side of the white area. I can't seem to find a way to completely remove the black values.
So my question is - is there a way to completely remove these values from the rgb matrix, or will I have to try to find a work around using NaN values or some other equivalent? My apologies if the question is too ambiguous.
slicer.png

채택된 답변

Subhadeep Koley
Subhadeep Koley 2020년 2월 6일
You can achieve this via ROI processing and defining a function handle. See the demo code below. (Download the attached image)
clc; close all;
% Read your image
I = imread('slicerNew.png');
% Create binary mask from it
BW = imbinarize(rgb2gray(I));
% Define your own function handle here (e.g., your gradient tool, etc.)
fun = @(n)imnoise(n, 'salt & pepper', 0.9);
% Apply filter only on the white portion of the BW mask
filteredImg = zeros(size(I));
for idx = 1:3
filteredImg(:, :, idx) = roifilt2(I(:, :, idx), BW, fun);
end
% Display filtered image
imshow(filteredImg, []);

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by