Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Matlab image processing issue

Status
Not open for further replies.

MohamedX17

Newbie level 1
Joined
Feb 10, 2014
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
9
I am not sure whether this is the right section or not
Recently I've started to self study Image processing using matlab for more precision I am trying to do chroma keying the two pictures in the attachment and here is my code
Code:
clc
clear
close all
rgb = imread('ninjagreen.jpg');
rgb=double(rgb)/255;
inds=((rgb(:,:,2)<=.58));
rgb(:,:,1)=rgb(:,:,1).*inds;
rgb(:,:,2)=rgb(:,:,2).*inds;
rgb(:,:,3)=rgb(:,:,3).*inds;
image(rgb)
red=rgb(:,:,1);
green=rgb(:,:,2);
blue=rgb(:,:,3);
redin=find(red~=0);
greenin=find(green~=0);
bluein=find(blue~=0);
forest=imread('forest.jpg');
forest=double(forest)/255;
forest_R=forest(:,:,1);
forest_G=forest(:,:,2);
forest_B=forest(:,:,3);
forest_R(redin)=red(redin);
forest_G(greenin)=green(greenin);
forest_B(bluein)=blue(bluein);
forest(:,:,1)=forest_R;
forest(:,:,2)=forest_G;
forest(:,:,3)=forest_B;
image(forest)
There is a problem in the matrix re-sizing so any idea how to fix that and Thanks in advance.
 

Attachments

  • ninjagreen.jpg
    ninjagreen.jpg
    29.3 KB · Views: 77
  • forest.jpg
    forest.jpg
    256.5 KB · Views: 77

First of all, your code formatting is terrible. Space it out. Use comments. Try something like this:

Code:
close all; clear all; clc;

% --- Load NINJA image ---
rgb = imread('ninjagreen.jpg');
rgb = double(rgb)/255;

% Blacken all pixels with green > 0.58
inds = rgb(:,:,2) <= .58;
rgb(:,:,1) = rgb(:,:,1).*inds;
rgb(:,:,2) = rgb(:,:,2).*inds;
rgb(:,:,3) = rgb(:,:,3).*inds;

% Display modified image
image(rgb);

% Extract red, green and blue components
red = rgb(:,:,1);
green = rgb(:,:,2);
blue = rgb(:,:,3);

% Get indices of pixels with non-zero r, g and b
redin = find(red~=0);
greenin = find(green~=0);
bluein = find(blue~=0);


% --- Load FOREST image ---
forest = imread('forest.jpg');
forest = double(forest)/255;

% Extract red, green and blue components
forest_R = forest(:,:,1);
forest_G = forest(:,:,2);
forest_B = forest(:,:,3);

% ??? Index the forest image with ninja image's non-zero r, g and b ??? 
forest_R(redin) = red(redin);
forest_G(greenin) = green(greenin);
forest_B(bluein) = blue(bluein);

% Copy results back to image data
forest(:,:,1) = forest_R;
forest(:,:,2) = forest_G;
forest(:,:,3) = forest_B;

% Display modified image
image(forest)

The first problem is that you are indexing the "forest" image with values obtained from the "ninja" image. This is probably not what you mean to do. What are you trying to do?
 
Last edited:

HI,

I would like to rescale a disparity depth map results based on the requirements from Middlebury website (https://vision.middlebury.edu/stereo/submit/) from the range of 4 to 16. Below is the coding of a stereo matching algorithm i applied on a pair of stereo images


Code:
a = vision.ImageDataTypeConverter; %creates the object converts the input image to a single precision data type.
b = vision.ColorSpaceConverter('Conversion','RGB to intensity');
leftI3 = step(a,imread('venusl.ppm')); % step = step response of dynamic system
leftI = step(b,leftI3);
rightI3 = step(a,imread('venusr.ppm'));
rightI = step(b,rightI3);

%*******************************************************************Basic_Block_Matching******************************************************************************************************
Dbasic = zeros(size(leftI), 'single');
disparityRange = 30;
% Selects (2*halfBlockSize+1)-by-(2*halfBlockSize+1) block
halfBlockSize = 3;
blockSize = 2*halfBlockSize+1; %7X7 block
% Allocate space for all template matcher System objects.
tmats = cell(blockSize);

% Initialize progress bar
hWaitBar = waitbar(0, 'Performing basic block matching...');
nRowsLeft = size(leftI, 1); 

% Scan over all rows.
for m=1:nRowsLeft
    % Set min/max row bounds for image block.
    minr = max(1,m-halfBlockSize);
    maxr = min(nRowsLeft,m+halfBlockSize);
    % Scan over all columns.
    for n=1:size(leftI,2)
        minc = max(1,n-halfBlockSize);
        maxc = min(size(leftI,2),n+halfBlockSize);
        % Compute disparity bounds.
        mind = max( -disparityRange, 1-minc );
        maxd = min( disparityRange, size(leftI,2)-maxc );

        % Construct template and region of interest.
        template = rightI(minr:maxr,minc:maxc);
        templateCenter = floor((size(template)+1)/2);
        roi = [minc+templateCenter(2)+mind-1 ...
               minr+templateCenter(1)-1 ...
               maxd-mind+1 1];
        % Lookup proper TemplateMatcher object; create if empty.
        if isempty(tmats{size(template,1),size(template,2)})
            tmats{size(template,1),size(template,2)} = ...
                vision.TemplateMatcher('ROIInputPort',true);
        end
        thisTemplateMatcher = tmats{size(template,1),size(template,2)};

        % Run TemplateMatcher object.
        loc = step(thisTemplateMatcher, leftI, template, roi);
        Dbasic(m,n) = loc(1) - roi(1) + mind;
    end
    waitbar(m/nRowsLeft,hWaitBar);
end

close(hWaitBar);

figure(3), clf;
imshow(Dbasic,[]), axis image, colormap('jet'), colorbar;
caxis([0 disparityRange]);
title('Depth map from basic block matching');

%********************************************************************************************************************************


What should i add in the coding to rescale the the depth map of figure(3) and save is as a file?
Please help, thanks a lot!!
 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top