matlab - error while masking an image -
i want threshold before applying algorithm.i tried in 1 algorithm , got perfect result.but here considered binary image , masking.i want intervertebral disc(ellipse portion) in between vertebrae .can suggest other method?
close all; clear all; %% img = imread('sub.png'); img=rgb2gray(img);%convert single channel data not contain color image img=im2bw(img,.16); fig1=figure; subplot(221) imshow(img); title('original image') m1 = uint8(img>35); subplot(222), imshow(m1,[]); title('mask m1'); m2=uint8(img<300); subplot(223), imshow(m2,[]); title('mask m2'); sd = stdfilt( double(img), ones(3,3)); m3= uint8(sd<18); subplot(224), imshow(m3,[]); title('mask m3'); fig2=figure; = uint8(img.* m1); = uint8(i.* m2); = uint8(i.* m3); subplot(221), imshow(i); title('masked img')
i'm getting error as
i cannot view mask1 , mask 2, mask3 , i'm getting error error using .* integers can combined integers of same class, or scalar doubles.
error in test1 (line 22)
corrected code is
close all; clear all; %% img = imread('sub.png'); img=rgb2gray(img);%convert single channel data not contain color image img=im2bw(img,.16); fig1=figure; subplot(221) imshow(img); title('original image') m1 = uint8(img>35); subplot(222), imshow(m1,[]); title('mask m1'); m2=uint8(img<300); subplot(223), imshow(m2,[]); title('mask m2'); sd = stdfilt( double(img), ones(3,3)); m3= uint8(sd<18); subplot(224), imshow(m3,[]); title('mask m3'); fig2=figure; img(~m1)=0; img(~m2)=0; img(~m3)=0; subplot(221), imshow(img); title('masked img')
there multiple issues code. while applying mask using multiplication technically possible, recommend use indexing instead:
img(~mask)=0;
this code sets every pixel not in mask zero.
there issue code. using uint8
uint8 image, function not rescale. if input normalized double image (values between 0 , 1) end black image because contains 0 , 1 values. use im2uint8
convert images, think trying here done on double image well.
Comments
Post a Comment