Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
translate image to zero gray value background

Subject: translate image to zero gray value background

From: marlina

Date: 12 Aug, 2010 05:16:05

Message: 1 of 3

Hi all,

here is my code:

clc;%close all;%clear all;
I = imread('.\image\picture6a.jpg');

Igray = rgb2gray(I); % convert image to grayscale
Imul=immultiply(Igray,1.0); % do some contrast balancing

Inoise = imnoise(Imul,'salt & pepper',0.01);
Imed = medfilt2(Inoise,[3 3]); % noise distortion using median filter

Iedge=edge(Imed, 'canny',[0.09 0.6],1.5); % edge detection using canny
figure(1),imshow(Iedge)

figure(2),imshow(Imed,[]); %boundary tracing
s=size(Iedge);
for row = 2:5:s(1)
   for col=1:s(2)
      if Iedge(row,col),
         break;
      end
   end

   contour = bwtraceboundary(Iedge, [row, col], 'S', 8, inf,...
                                   'counterclockwise');
   if(~isempty(contour))
      hold on;
      plot(contour(:,2),contour(:,1),'g','LineWidth',2);
      hold on;
      plot(col, row,'gx','LineWidth',2);

   end
end

From figure (1)---it will show edge of the hand (bw image- only edge of the hand is in white color, others is black including foreground of the hand)
         figure (2)---it will show detection of edge at grayscale image

So, my question is how i am going to translate edge detection image from grayscale image into picture 2 (where the background is black) and use edge detection from figure 2 as a reference.

summary of my question: background is black and hand region is in grayscale

Thank you...i really need the answer....plzzz

Subject: translate image to zero gray value background

From: Sean

Date: 12 Aug, 2010 13:00:18

Message: 2 of 3

"marlina " <marlinayakno@gmail.com> wrote in message <i4002l$ib3$1@fred.mathworks.com>...
> Hi all,
>
> here is my code:
>
> clc;%close all;%clear all;
> I = imread('.\image\picture6a.jpg');
>
> Igray = rgb2gray(I); % convert image to grayscale
> Imul=immultiply(Igray,1.0); % do some contrast balancing
>
> Inoise = imnoise(Imul,'salt & pepper',0.01);
> Imed = medfilt2(Inoise,[3 3]); % noise distortion using median filter
>
> Iedge=edge(Imed, 'canny',[0.09 0.6],1.5); % edge detection using canny
> figure(1),imshow(Iedge)
>
> figure(2),imshow(Imed,[]); %boundary tracing
> s=size(Iedge);
> for row = 2:5:s(1)
> for col=1:s(2)
> if Iedge(row,col),
> break;
> end
> end
>
> contour = bwtraceboundary(Iedge, [row, col], 'S', 8, inf,...
> 'counterclockwise');
> if(~isempty(contour))
> hold on;
> plot(contour(:,2),contour(:,1),'g','LineWidth',2);
> hold on;
> plot(col, row,'gx','LineWidth',2);
>
> end
> end
>
> From figure (1)---it will show edge of the hand (bw image- only edge of the hand is in white color, others is black including foreground of the hand)
> figure (2)---it will show detection of edge at grayscale image
>
> So, my question is how i am going to translate edge detection image from grayscale image into picture 2 (where the background is black) and use edge detection from figure 2 as a reference.
>
> summary of my question: background is black and hand region is in grayscale
>
> Thank you...i really need the answer....plzzz

%%%
So your gray image is uint8, that means white is intensity 255:
Igray(Iedge) = 255;

Subject: translate image to zero gray value background

From: marlina

Date: 13 Aug, 2010 03:28:05

Message: 3 of 3

Hi Sean,

Thank you for your suggestion....but that's not my aim.
 from your code : Igray(Iedge) = 255;
the outline of the hand edge from figure 1(canny edge detection) will be translate into into grayscale image.

my objective ito translate grayscale image of hand into figure 2 (canny edge detection)...its look like you crop the hand image form grayscale image into figure 2....so the hand image is in grayscale and background is black. I hope you can understand my objective.

Thank you so much...Looking forward for any suggestion..


Marlina

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us