Reputation: 619
Suppose I have two input images. One only contains three colors such as green, red, and blue as labels. Another image that needs to be edited based on the colors in the first image. So, for instance, wherever the label image is red, I'd like function A
to happen on the original image.
To do this, I would like to create a lookup that gets a color as input and outputs a function to be executed on the original image.
What's the best way to go about this?
Upvotes: 0
Views: 805
Reputation: 45752
You can use logical indexing for this.
im1 = [0 0 1;
1 2 0;
2 2 1];
im2 = rand(3);
find where im1
equals 1
:
idx = im1 == 1;
idx
is now a matrix of logicals which can act as a mask for im2
:
idx =
0 0 1
1 0 0
0 0 1
do something to all the corresponding pixels of im2
:
im2(idx) = im2(idx) + 5;
Also, although I doubt this is what you were asking, you could define your function A
using anonymous functions:
A = @(x)(2.*x.^2 - x + 5)
im2(idx) = A(im2(idx))
Upvotes: 2