Segment structure using threshold

I need to extract the texture.for that,first I have set 5 thresholds. For each pixel,checked if they are between any thresholds,then the pixel value is replaced by lower threshold value index of the two.now it is told that they would give a segmented structure of the actual figure.But I not getting,please any help me

4 件のコメント

Gopichandh Danala
Gopichandh Danala 2018 年 4 月 9 日
provide your current version of code, sample image that you want segment.
Devika D
Devika D 2018 年 4 月 9 日
編集済み: Walter Roberson 2018 年 4 月 9 日
close all;
clear all;
I = imread('E:\desktop\seminar\bradtz data base\brojpeg\D41.jpg');
I2=imcrop(I,[160 160 160 160]);
[m,n]=size(I2);
figure
imshow(I2);
k=input('enter k');
t(1)=min(min(I2));
t(k)=max(max(I2));
tm=mean2(I2);
for i=2:((k+1)/2)-1
t(i)=(t(i-1)+tm)/2;
end
t((k+1)/2)=tm;
for i=(((k+1)/2)+1):k-1
t(i)=(t(i-1)+t(k))/2;
end
for i=1:k-1
for x=1:m
for y=1:n
if I2(x,y)==t(i)
w(x,y)=i;
else
if I2(x,y)>t(i) && I2(x,y)<=t(i+1)
w(x,y)=i;
end
end
end
end
end
figure
imshow(w);
*a is the input and c must be output *
Hope you understood
Gopichandh Danala
Gopichandh Danala 2018 年 4 月 10 日
編集済み: Gopichandh Danala 2018 年 4 月 10 日
I am not clear about what you meant by 'extract texture'. I am answering with the assumption that you want to segment either with a single threshold (global threshold) or use a multi-level threshold to segment multiple regions..
img = rgb2gray(imread('image.jpg'));
figure, imshow(img,[])
% global otsu thresholding
level=graythresh(img);
BW=imbinarize(img,level);
figure, imshow(BW,[])
% I am not sure if you are looking for something like this?
num_threshs = 5;
% Set five thresholds..
% (I used Multilevel image thresholds using Otsu’s method )
thresh = multithresh(img,num_threshs);
% Extract five threshold images
img1 = img <= thresh(1);
img2 = and(img <= thresh(2),img > thresh(1));
img3 = and(img <= thresh(3), img > thresh(2));
img4 = and(img <= thresh(4), img > thresh(3));
img5 = and(img <= thresh(5), img > thresh(4));
img6 = img > thresh(5);
figure,
subplot(231), imshow(img1,[]), title('img <= T1')
subplot(232), imshow(img2,[]), title('img > T1 && img <= T2')
subplot(233), imshow(img3,[]), title('img > T2 && img <= T3')
subplot(234), imshow(img4,[]), title('img > T3 && img <= T4')
subplot(235), imshow(img5,[]), title('img > T4 && img <= T5')
subplot(236), imshow(img6,[]), title('img > T5')
Or use imquantize.
quantize_img = imquantize(img,thresh);
figure,
subplot(121), imshow(quantize_img,[]), title('Quantized image')
subplot(122), imshow(label2rgb(quantize_img),[]), title('Quantized color image')
Devika D
Devika D 2018 年 4 月 10 日
編集済み: Devika D 2018 年 4 月 10 日
sir,
Actually I am trying to capture the segmented structure of the image.
from the figure if 'a' is the actual image matrix,then b the 5 thresholds.after applying the threshold I must get as in the figure that I have already shown above. hope you got my idea.

サインインしてコメントする。

回答 (1 件)

Gopichandh Danala
Gopichandh Danala 2018 年 4 月 10 日
編集済み: Gopichandh Danala 2018 年 4 月 10 日

1 投票

Quantize does what you are expecting.
It will divide the given image into a number of labels based on thresh values as shown in the above image.
Here I am using multithresh function to obtain five threshold values.
So, I will have 6 possible ranges (i.e. less than <T1, T1-T2, T2-T3, T3-T4, T4-T5,>T5 = 6 possible labels you can adjust this)
img = rgb2gray(imread('image.jpg'));
num_threshs = 5;
thresh = multithresh(img,num_threshs);
quantize_img = imquantize(img,thresh);
figure,
subplot(221), imshow(img,[]), title('orig-image')
subplot(222), imshow(quantize_img,[]), title('Quantized image')
subplot(2,2,[3,4]), histogram(quantize_img), title('Each pixel labelled 1-to-6')
unique(quantize_img)
ans =
1
2
3
4
5
6
If you want to give the 5 thresholds manually, just create an array yourself and pass it.
manual_thresh = [20, 40, 60, 80 ,100] # change this
quantize_img = imquantize(img,manual_thresh);
If you want to manually do it as shown in above figure
img = rgb2gray(imread('crop1.jpg'));
num_threshs = 5;
%thresh = multithresh(img,num_threshs); [32 52 86 128 173]
thresh = [min(img(:)),52,86,128, max(img(:))]; % to cover full range of img
label_img = zeros(size(img));
label_img(and(img < thresh(2),img >= thresh(1))) = 1;
label_img(and(img < thresh(3),img >= thresh(2))) = 2;
label_img(and(img < thresh(4),img >= thresh(3))) = 3;
label_img(and(img <= thresh(5),img >= thresh(4))) = 4;
figure,
subplot(121), imshow(img,[]), title('orig-image')
subplot(122), imshow(label_img,[]), title('label-image')

2 件のコメント

Devika D
Devika D 2018 年 4 月 11 日
編集済み: Devika D 2018 年 4 月 11 日
Thank you sir,
I think got the correct answer
Gopichandh Danala
Gopichandh Danala 2018 年 4 月 23 日
If this answer solves your problem please accept the answer so others find it useful

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

質問済み:

2018 年 4 月 9 日

コメント済み:

2018 年 4 月 23 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by