MATLAB Answers

Manipulation of RGB matrices possibly using NaN values?

3 views (last 30 days)
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

  0 Comments

Sign in to comment.

Accepted Answer

Subhadeep Koley
Subhadeep Koley on 6 Feb 2020
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 Comments

Sign in to comment.

More Answers (0)

Tags


Translated by