My problem is when putting the pictures together my indices have to be an integer so how do I take a third of each picture and put them together?
2 次查看(过去 30 天)
显示 更早的评论
Hi, I'm trying to make a red filter by picking a value between 0 and 1 and dividing the remainder to the Green and Blue layers of the picture then stitching together a grayscale, the original, and the red filtered picture next to each other...
function [ outImg] = redFilter( inImg , redVal)
%red filter
[r,c,d] = size(inImg);
%grayscale
gray = 0.2989*inImg(:,:,1)+0.5870*inImg(:,:,2)+0.1140*inImg(:,:,3);
%red filter
GandB = 1 - redVal;
red = redVal*inImg(:,:,1)+(GandB/2)*inImg(:,:,2)+(GandB/2)*inImg(:,:,3);
%final image
gray3 = gray(r,round(c/3),d);
red3 = red(r,c/3,d);
inImg3 = InImg(r,c/3,d);
outImg = [gray3, inImg3, red3];
end
2 个评论
Stephen23
2017-3-5
@Brady Barkemeyer: this time I formatted your code for you. Next time you can do it yourself: first select the code text, then click the Code {} button above the textbox.
Jan
2017-3-6
The question is not clear to me. What does "take a third" exactly mean? Do you mean something like gray(r, 1:3:end, d)?
回答(1 个)
Sonam Gupta
2017-3-8
I assume that you are trying to stitch the images together such that for the same image 1/3rd is in grayscale, another 1/3rd is redFiltered and remaining 1/3rd is real image. Few points to pay attention are gray is a two dimensional matrix having same dimension as that of image size. By using the syntax 'gray(r,round(c/3),d)' you are referring to single element of the array. Moreover, the way gray is defined it does not have third dimension.
Given below is the modified version of your code but you still need to check what you want to achieve with gray.
function [ outImg] = redFilter_modified( inImg , redVal)
%red filter
[r,c,d] = size(inImg);
%grayscale
gray = zeros(r, c, d);
gray(:, : , 1) = 0.2989*inImg(:,:,1);
gray(:, :, 2) = 0.5870*inImg(:,:,2);
gray(:, :,3) = 0.1140*inImg(:,:,3);
%red filter
GandB = 1 - redVal;
red = zeros(r, c, d);
red(:, :, 1) = redVal*inImg(:,:,1);
red(:, :,2) = (GandB/2)*inImg(:,:,2);
red(:, :, 3) = (GandB/2)*inImg(:,:,3);
%final image
%creating the image array taking one third from all there matrices
width = round(c/3); % number of rows should be same, only number of columns will be divided by 3
gray3 = gray(:,1:width, :);
red3 = red(:,width+1: round(2*c/3), :);
inImg3 = inImg(:,round((2*c/3)+1 : c), :);
outImg = [gray3,red3, inImg3];
imshow(outImg);
end
Hope this answers your query.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!